Przeciążenie C ++ przez typ licznika parame- trów functor
Pracuję nad biblioteką „LINQ to Objects” dla C ++ 11. Chciałbym zrobić coś takiego:
<code>// 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; } ) </code>
Chciałbym napisaćarr.where_i( ... )
- jest brzydki. Potrzebuję przeciążenia funkcji / metody przez typ lambda ...
To jest moje rozwiązanie:
<code>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 } </code>
Czy to rozwiązanie SFINAE? Co możesz mi zaproponować?