私はC++ 11用の「LINQ to Objects」ライブラリに取り組んでいます。私はこのようなことをしたいと思います:
// filtering elements by their value
arr.where( [](double d){ return d < 0; } )
// filtering elements by their value and position
arr.where( [](double d, int i){ return i%2==0; } )
私は書きたいですarr.where_i( ... )
-それは醜いです。したがって、ラムダ型による関数/メソッドのオーバーロードが必要です...
これが私の解決策です:
template<typename F>
auto my_magic_func(F f) -> decltype(f(1))
{
return f(1);
}
template<typename F>
auto my_magic_func(F f, void * fake = NULL) -> decltype(f(2,3))
{
return f(2,3);
}
int main()
{
auto x1 = my_magic_func([](int a){ return a+100; });
auto x2 = my_magic_func([](int a, int b){ return a*b; });
// x1 == 1+100
// x2 == 2*3
}
SFINAEソリューションですか?あなたは私に何を提案できますか?