Revamp EnableIf and DisableIf to use a much better variadic condition checking

This commit is contained in:
Rapptz 2014-05-31 22:04:10 -04:00
parent eedb2a1796
commit 76b1efe12e
2 changed files with 25 additions and 13 deletions

View File

@ -57,13 +57,13 @@ public:
return *this;
}
template<typename U>
EnableIf<Function<Unqualified<U>>> operator=(U&& other) {
template<typename U, EnableIf<Function<Unqualified<U>>> = 0>
void operator=(U&& other) {
tbl.set_function(key, std::forward<U>(other));
}
template<typename U>
DisableIf<Function<Unqualified<U>>> operator=(U&& other) {
template<typename U, DisableIf<Function<Unqualified<U>>> = 0>
void operator=(U&& other) {
tbl.set(key, std::forward<U>(other));
}
@ -129,6 +129,6 @@ inline bool operator!= (const proxy<Table, Key>& right, T&& left) {
return right.template get<Decay<T>>() != left;
}
} // sol
} // sol
#endif // SOL_PROXY_HPP

View File

@ -32,11 +32,26 @@ struct are_same : std::true_type { };
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> { };
template<typename T, typename R = void>
using EnableIf = typename std::enable_if<T::value, R>::type;
template<bool B>
using Bool = std::integral_constant<bool, B>;
template<typename T, typename R = void>
using DisableIf = typename std::enable_if<!T::value, R>::type;
template<typename T>
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>
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>
struct is_specialization_of<Templ<T...>, Templ> : std::true_type { };
template<bool B>
using Bool = std::integral_constant<bool, B>;
namespace detail {
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};