Created
August 9, 2015 05:45
-
-
Save Fuyutsubaki/95ba4de7bde5e776eb94 to your computer and use it in GitHub Desktop.
ordered overload function oject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace alol{ | |
template<class...T> | |
class ordered_poly_lambda | |
{ | |
struct stop{}; | |
public: | |
void operator()(stop){} | |
}; | |
template<class F, class ...T> | |
class ordered_poly_lambda<F, T...> | |
{ | |
F f; | |
ordered_poly_lambda<T...> rest; | |
template<class ...Args> | |
auto call(int, Args&&...args) | |
->decltype(std::forward<F>(f)(std::forward<Args>(args)...)) | |
{ | |
return std::forward<F>(f)(std::forward<Args>(args)...); | |
} | |
template<class ...Args> | |
auto call(double, Args&&...args) | |
->decltype(rest(std::forward<Args>(args)...)) | |
{ | |
return rest(std::forward<Args>(args)...); | |
} | |
public: | |
ordered_poly_lambda(F&& f, T&&... args) | |
:f(std::forward<F>(f)), rest(std::forward<T>(args)...) | |
{} | |
template<class ...Args> | |
auto operator()(Args&&...args) | |
->decltype(call(0, std::forward<Args>(args)...)) | |
{ | |
return call(0, std::forward<Args>(args)...); | |
} | |
}; | |
template<class...F> | |
ordered_poly_lambda<F...> make_poly(F&&...f) | |
{ | |
return{ std::forward<F>(f)... }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment