Search code examples
c++c++11lambdafunctorstd

Can lambdas be STL-adaptable?


"Make functor classes adaptable" - told Scott Meyers in Effective STL, item 40. There is a question - can lambda-functions be adaptable? (Lambdas doesn't provide access to the inheritance mechanism, right?)


Solution

  • That item is not talking about inheritance, but about composition.

    Prior to C++11, if you wanted to invert the output of a unary predicate, you would define argument_type and result_type member types, so you could wrap it in std::not1.

    Or if you wanted to partially apply a binary operation, you would define first_argument_type, second_argument_type and result_type, to pass it to std::bind1st or std::bind2nd.

    You don't get to add members to a lambda's type, so you can't use them with the old adaptors.