Having written a general minimal function, two questions occurred to me. The code works fine with any type of input and another argument number:
namespace xyz { template <typename T1, typename T2> auto min(const T1 &a, const T2 &b) -> decltype(a+b) { return a < b ? a : b; } template <typename T1, typename T2, typename ... Args> auto min(const T1 &a, const T2 &b, Args ... args) -> decltype(a+b) { return min(min(a, b), args...); } } int main() { cout << xyz::min(4, 5.8f, 3, 1.8, 3, 1.1, 9) << endl;
Is there a better replacement for decltype(a+b) ? I have a standard class there that I donβt remember, something like decltype(std::THE_RESULT<a,b>::type) .
The return type of this decltype(std::THE_RESULT<a,b>::type) is equal to const & or not?
c ++ c ++ 11
deepmax May 11 '13 at 14:12 2013-05-11 14:12
source share