mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Revamp EnableIf and DisableIf to use a much better variadic condition checking
This commit is contained in:
parent
eedb2a1796
commit
76b1efe12e
|
@ -57,13 +57,13 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U, EnableIf<Function<Unqualified<U>>> = 0>
|
||||||
EnableIf<Function<Unqualified<U>>> operator=(U&& other) {
|
void operator=(U&& other) {
|
||||||
tbl.set_function(key, std::forward<U>(other));
|
tbl.set_function(key, std::forward<U>(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U, DisableIf<Function<Unqualified<U>>> = 0>
|
||||||
DisableIf<Function<Unqualified<U>>> operator=(U&& other) {
|
void operator=(U&& other) {
|
||||||
tbl.set(key, std::forward<U>(other));
|
tbl.set(key, std::forward<U>(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,26 @@ struct are_same : std::true_type { };
|
||||||
template<class T, class U, class... Args>
|
template<class T, class U, class... Args>
|
||||||
struct are_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value && are_same<T, Args...>::value> { };
|
struct are_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value && are_same<T, Args...>::value> { };
|
||||||
|
|
||||||
template<typename T, typename R = void>
|
template<bool B>
|
||||||
using EnableIf = typename std::enable_if<T::value, R>::type;
|
using Bool = std::integral_constant<bool, B>;
|
||||||
|
|
||||||
template<typename T, typename R = void>
|
template<typename T>
|
||||||
using DisableIf = typename std::enable_if<!T::value, R>::type;
|
using Not = Bool<!T::value>;
|
||||||
|
|
||||||
|
template<typename Condition, typename Then, typename Else>
|
||||||
|
using If = typename std::conditional<Condition::value, Then, Else>::type;
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
struct And : Bool<true> {};
|
||||||
|
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
struct And<T, Args...> : If<T, And<Args...>, Bool<false>> {};
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
using EnableIf = typename std::enable_if<And<Args...>::value, int>::type;
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
using DisableIf = typename std::enable_if<Not<And<Args...>>::value, int>::type;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using Unqualified = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
using Unqualified = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
||||||
|
@ -70,9 +85,6 @@ struct is_specialization_of : std::false_type { };
|
||||||
template <typename... T, template <typename...> class Templ>
|
template <typename... T, template <typename...> class Templ>
|
||||||
struct is_specialization_of<Templ<T...>, Templ> : std::true_type { };
|
struct is_specialization_of<Templ<T...>, Templ> : std::true_type { };
|
||||||
|
|
||||||
template<bool B>
|
|
||||||
using Bool = std::integral_constant<bool, B>;
|
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
||||||
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};
|
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user