Can lambda expressions be used as class template parameters? (Note that this is a completely different question than this , which asks if there can be a wildcard expression on its own.)
I ask if you can do something like:
template <class Functor> struct Foo { };
This would be useful in cases where, for example, the class template has various parameters, such as equal_to or something else, which are usually implemented as single-line functors. For example, suppose I want to create a hash table instance that uses my own match comparison function. I would like to say something like:
typedef std::unordered_map< std::string, std::string, std::hash<std::string>, decltype([](const std::string& s1, const std::string& s2)->bool { }) > map_type;
But I tested this on GCC 4.4 and 4.6, and it does not work, apparently because the anonymous type created by the lambda expression does not have a default constructor. (I recall a similar problem with boost::bind .) Is there any reason why the draft standard does not allow this, or am I mistaken and allowed, but does GCC simply lag behind in their implementation?
c ++ lambda c ++ 11 templates
Channel72 May 01 '11 at 14:45 2011-05-01 14:45
source share