But I want that the lambda would depend on the first template parameter of the function.
четверг, 3 октября 2013 г., 3:56:53 UTC+4 пользователь Richard Smith написал:On Wed, Oct 2, 2013 at 4:46 PM, Vlad from Moscow <vlad....@mail.ru> wrote:
Can someone point at where in the C++ Standard there is said that a lambda expression may not be a default template argument.I tried to compile the following declaration with using GCC and I got a compilation errortemplate <class T,
class U = []( const T & ){ return ( true ); }>A lambda-expression is an expression, not a type. Maybe you meant:auto x = []( const T & ){ return ( true ); };template <class T, class U = decltype(x)>void f(U u = x);
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.
template <class T, class U = decltype([](const T&){return true;})>
void f(U u = U());
2013. október 3., csütörtök 1:46:32 UTC+2 időpontban Vlad from Moscow a következőt írta:Can someone point at where in the C++ Standard there is said that a lambda expression may not be a default template argument.I tried to compile the following declaration with using GCC and I got a compilation errortemplate <class T,
class U = []( const T & ){ return ( true ); }>void f( U u = U() );Problem with the workarounds posted, that they not necessary work everywhere: I'm thinking of inside a class definition: if you wanted your void f() function template to be a class member, you have to find another way to do this some another way (overloading or specialization).
Lambdas cannot appear in unevaluated contexts, that's why it doesn't compile, even if you put decltype around the lambda:
Also, the "=U()" part won't work as well, not even in C++14. I had the proposal for default constructor of closures a while back, but didn't pursue it because of this unevaluated context part. What is a shame, the new generic captures and polymorphic arguments make lambdas an insanely powerful tool to define functors, would be awesome if we could use them as template arguments.
template <class T, class U = decltype([](const T&){return true;})>
void f(U u = U());
Regards, Robert
--
On Thu, Oct 3, 2013 at 1:27 PM, Róbert Dávid <lrd...@gmail.com> wrote:
2013. október 3., csütörtök 1:46:32 UTC+2 időpontban Vlad from Moscow a következőt írta:Can someone point at where in the C++ Standard there is said that a lambda expression may not be a default template argument.I tried to compile the following declaration with using GCC and I got a compilation errortemplate <class T,
class U = []( const T & ){ return ( true ); }>void f( U u = U() );Problem with the workarounds posted, that they not necessary work everywhere: I'm thinking of inside a class definition: if you wanted your void f() function template to be a class member, you have to find another way to do this some another way (overloading or specialization).Both a generic lambda and a static data member template still work in that context.
2013. október 3., csütörtök 22:36:27 UTC+2 időpontban Richard Smith a következőt írta:On Thu, Oct 3, 2013 at 1:27 PM, Róbert Dávid <lrd...@gmail.com> wrote:
2013. október 3., csütörtök 1:46:32 UTC+2 időpontban Vlad from Moscow a következőt írta:Can someone point at where in the C++ Standard there is said that a lambda expression may not be a default template argument.I tried to compile the following declaration with using GCC and I got a compilation errortemplate <class T,
class U = []( const T & ){ return ( true ); }>void f( U u = U() );Problem with the workarounds posted, that they not necessary work everywhere: I'm thinking of inside a class definition: if you wanted your void f() function template to be a class member, you have to find another way to do this some another way (overloading or specialization).Both a generic lambda and a static data member template still work in that context.
How exactly? I have failed to have it compiled: http://ideone.com/WDVc9f