Suppose I have a type my_structcontaining a member variable f, which is a function. Possibly what fis the lambda function of C ++ 11.
Since assigning lambda objects is illegal, I would like to implement an assignment operator my_structsuch that when it fis a lambda, it is not assigned.
Is it possible to build a type trait is_lambdathat can check the type for a lambda error?
In code:
#include <type_traits>
template<typename Function> struct is_lambda
{
};
template<typename Function> struct my_struct
{
Function f;
my_struct &do_assign(const my_struct &other, std::true_type)
{
return *this;
}
my_struct &do_assign(const my_struct &other, std::false_type)
{
f = other.f;
return *this;
}
my_struct &operator=(const my_struct &other)
{
return do_assign(other, typename is_lambda<Function>::type());
}
};
source
share