From 76b1efe12e6f842a9244ff8309963a4f82f87de6 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 31 May 2014 22:04:10 -0400 Subject: [PATCH] Revamp EnableIf and DisableIf to use a much better variadic condition checking --- sol/proxy.hpp | 12 ++++++------ sol/traits.hpp | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/sol/proxy.hpp b/sol/proxy.hpp index 8dc20d13..b30e558d 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -57,13 +57,13 @@ public: return *this; } - template - EnableIf>> operator=(U&& other) { + template>> = 0> + void operator=(U&& other) { tbl.set_function(key, std::forward(other)); } - template - DisableIf>> operator=(U&& other) { + template>> = 0> + void operator=(U&& other) { tbl.set(key, std::forward(other)); } @@ -129,6 +129,6 @@ inline bool operator!= (const proxy& right, T&& left) { return right.template get>() != left; } -} // sol - +} // sol + #endif // SOL_PROXY_HPP diff --git a/sol/traits.hpp b/sol/traits.hpp index daddd3f8..f4bbc29a 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -32,11 +32,26 @@ struct are_same : std::true_type { }; template struct are_same : std::integral_constant ::value && are_same::value> { }; -template -using EnableIf = typename std::enable_if::type; +template +using Bool = std::integral_constant; -template -using DisableIf = typename std::enable_if::type; +template +using Not = Bool; + +template +using If = typename std::conditional::type; + +template +struct And : Bool {}; + +template +struct And : If, Bool> {}; + +template +using EnableIf = typename std::enable_if::value, int>::type; + +template +using DisableIf = typename std::enable_if>::value, int>::type; template using Unqualified = typename std::remove_cv::type>::type; @@ -70,9 +85,6 @@ struct is_specialization_of : std::false_type { }; template class Templ> struct is_specialization_of, Templ> : std::true_type { }; -template -using Bool = std::integral_constant; - namespace detail { template>::value> struct is_function_impl : std::is_function::type> {};