-
-
Save rmartinho/b8342e80137291625cbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
using Invoke = typename T::type; | |
// identity meta-function | |
template <typename T> | |
struct id { using type = T; }; | |
// `int` meta-constant | |
template <int I> | |
using Int = std::integral_constant<int, I>; | |
// `bool` meta-constant | |
template <bool B> | |
using Bool = std::integral_constant<bool, B>; | |
using True = Bool<true>; | |
using False = Bool<false>; | |
// if-then-else meta-function | |
template <typename Condition, typename Then, typename Else> | |
using Conditional = Invoke<std::conditional<Condition::value, Then, Else>>; | |
// Boolean negation meta-function | |
template <typename T> | |
using Not = Bool<!T::value>; | |
// | |
// Boolean disjunction meta-function | |
template <typename... T> | |
struct any : False {}; | |
template <typename Head, typename... Tail> | |
struct any<Head, Tail...> : Conditional<Head, True, any<Tail...>> {}; | |
template <typename... T> | |
using Any = Invoke<any<T...>>; | |
// Boolean conjunction meta-function | |
template <typename... T> | |
struct all : True {}; | |
template <typename Head, typename... Tail> | |
struct all<Head, Tail...> : Conditional<Head, all<Tail...>, False> {}; | |
template <typename... T> | |
using All = Invoke<all<T...>>; | |
// Conditional overload enabler | |
template <typename... T> | |
using EnableIf = Invoke<std::enable_if<All<T...>::value, int>>; | |
// Conditional overload disabler | |
template <typename... T> | |
using DisableIf = Invoke<std::enable_if<!Any<T...>::value, int>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment