title: Is a C++ is_lambda trait, purely implemented as a library, impossible?
body: <p>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:</p>
  
  <pre><code>struct foobar
  {
    void operator()()
    {
    }
  };
  
  auto lambda = []{};
  typedef is_lambda &lt; decltype(lambda) &gt; ::type T; // T would be a true_type
  typedef is_lambda &lt; foobar &gt; ::type T; // T would be a false_type
  </code></pre>
  
  <p>It is rather easy to distinguish lambda expressions from function and member function types. Functors are another matter.</p>
  
  <p>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 <em>not</em> 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:</p>
  
  <pre><code>typedef decltype(&amp;T::operator()) call_type;
  </code></pre>
  
  <p>will work for both lambda expressions and functors with non-templated call operator, and generate a compiler error for templated call operators.</p>
  
  <p>I believe an <code>is_lambda &lt; &gt;</code> trait can only be created using intrinsic compiler features. Do you see a way how to implement this trait?</p>