2

Is it allowed to use a lambda function as the default value of a template argument? The code fragment in question would be:

template <typename K, typename E, typename C = [](const K& l, const K& r) { return (l < r); }> class FooBar { typedef C compare_fn; }; 

If it's not, why so, and what could be the most passable alternative, aside from pointers to functions? TIA.

1 Answer 1

4

No. A lambda is an object, not a type.

One way to fix this is to use a named class, as in

template<typename K, typename E, typename C = std::less<K>> class FooBar { typedef C compare_fn; }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.