my_struct
関数であるメンバー変数を囲む型f
があるとします。f
が c++11 ラムダ関数になる可能性があります。
my_struct
ラムダ オブジェクトへの代入は違法なので、 がラムダの場合は代入されないようにの代入演算子を実装したいと思いますf
。
is_lambda
型のラムダ性を検査できる型特性を構築することは可能ですか?
コード内:
#include <type_traits>
template<typename Function> struct is_lambda
{
// what goes here?
};
template<typename Function> struct my_struct
{
Function f;
my_struct &do_assign(const my_struct &other, std::true_type)
{
// don't assign to f
return *this;
}
my_struct &do_assign(const my_struct &other, std::false_type)
{
// do assign to f
f = other.f;
return *this;
}
my_struct &operator=(const my_struct &other)
{
return do_assign(other, typename is_lambda<Function>::type());
}
};