KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a question regarding C++0x lambdas. In my code, it would be beneficial to know whether or not a given type is the type of a C++0x lambda expression. To give an example: struct foobar { void operator()() { } }; auto lambda = []{}; typedef is_lambda < decltype(lambda) > ::type T; // T would be a true_type typedef is_lambda < foobar > ::type T; // T would be a false_type It is rather easy to distinguish lambda expressions from function and member function types. Functors are another matter. The problem I see here is the definition of lambda expressions according to the upcoming C++0x standard; the only thing that must be defined is a public call operator. However, this is true for a functor as well; testing for the presence of the call operator is not enough for distinguishing lambda expressions from functors. Furthermore, if the operator of a functor is not present, a compiler error will occur, since SFINAE does not apply. When does this happen? The functor's call operator may be templated. So, such a code: typedef decltype(&T::operator()) call_type; will work for both lambda expressions and functors with non-templated call operator, and generate a compiler error for templated call operators. I believe an is_lambda < > trait can only be created using intrinsic compiler features. Do you see a way how to implement this trait?
Tags (comma-separated)
Save Edits
Cancel