From f8e23fd9ef9d4a65ba927b7c678d994e619a2a6f Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Sun, 26 Apr 2015 18:22:42 +0200 Subject: [PATCH] TMP magic to support gcc 4.7 --- include/mstch/mstch.hpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) 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) { }