[C++11] recursive late-specified return type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Could someone please clarify whether the following code (from [1]),
which GCC trunk rejects, is valid (i.e. the error is a bug) or invalid?

#include <iostream>
using namespace std;

template <class T>
T sum(const T& in)
{
   return in;
}

template <class T, class... P>
auto sum(const T& t, const P&... p) -> decltype(t + sum(p...))
{
   return t + sum(p...);
}

int main()
{
   cout << sum(5, 10.0, 22.2) << endl;
}

Errors:

test.cpp: In function 'int main()':
test.cpp:18:29: error: no matching function for call to 'sum(int, double, double)'
test.cpp:18:29: note: candidates are:
test.cpp:5:3: note: template<class T> T sum(const T&)
test.cpp:5:3: note:   template argument deduction/substitution failed:
test.cpp:18:29: note:   candidate expects 1 argument, 3 provided
test.cpp:11:6: note: template<class T, class ... P> decltype ((t + sum(sum::p ...))) sum(const T&, const P& ...)
test.cpp:11:6: note:   template argument deduction/substitution failed:
test.cpp: In substitution of 'template<class T, class ... P> decltype ((t + sum(p ...))) sum(const T&, const P& ...) [with T = int; P = {double, double}]':
test.cpp:18:29:   required from here
test.cpp:11:6: error: no matching function for call to 'sum(const double&, const double&)'
test.cpp:11:6: note: candidate is:
test.cpp:5:3: note: template<class T> T sum(const T&)
test.cpp:5:3: note:   template argument deduction/substitution failed:
test.cpp:11:6: note:   candidate expects 1 argument, 2 provided

Thanks,
Nate

[1] http://stackoverflow.com/questions/8023332/recursive-trailing-return-type)


 		 	   		  



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux