diff --git a/include/mstch/mstch.hpp b/include/mstch/mstch.hpp index 2679488..f09cbaa 100644 --- a/include/mstch/mstch.hpp +++ b/include/mstch/mstch.hpp @@ -8,6 +8,9 @@ #include namespace mstch { + +using renderer = std::function; + namespace internal { template @@ -34,19 +37,38 @@ class object_t { mutable std::map cache; }; -} +template +class is_fun { + private: + using not_fun = char; + using fun_without_args = char[2]; + using fun_with_args = char[3]; + template struct really_has; + template static fun_without_args& test( + really_has*); + template static fun_with_args& test( + really_has*); + template static not_fun& test(...); -using renderer = std::function; + public: + static bool const no_args = sizeof(test(0)) == sizeof(fun_without_args); + static bool const has_args = sizeof(test(0)) == sizeof(fun_with_args); +}; + +} class lambda { public: - lambda(std::function fun): - fun([fun](const std::string&, renderer){return fun();}) + template + lambda(F f, typename std::enable_if::no_args>::type* =0): + fun([f](const std::string&,renderer){return f();}) { } - lambda(std::function fun): - fun(fun) + template + lambda(F f, typename std::enable_if::has_args>::type* =0): + fun(f) { }