carl  24.04
Computer ARithmetic Library
SFINAE.h
Go to the documentation of this file.
1 /**
2  * @file SFINAE.h
3  * @author Sebastian Junges
4  *
5  * @since September 10, 2013
6  *
7  */
8 
9 #pragma once
11 #include <type_traits>
12 
13 namespace carl
14 {
15 
16 template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
17 template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
18 
19 #ifndef __VS
20 // from flamingdangerzone.com/cxx11/2012/05/29/type-traits-galore.html
21 template <bool If, typename Then, typename Else>
22 using Conditional = typename std::conditional<If, Then, Else>::type;
23 template <bool B, typename...>
24 struct dependent_bool_type : std::integral_constant<bool, B> {};
25 // and an alias, just for kicks :)
26 template <bool B, typename... T>
27 using Bool = typename dependent_bool_type<B, T...>::type;
28 
29 /// Meta-logical negation
30 template <typename T>
32 
33 /// Meta-logical disjunction
34 template <typename... T>
35 struct any : Bool<false> {};
36 template <typename Head, typename... Tail>
37 struct any<Head, Tail...> : Conditional<Head::value, Bool<true>, any<Tail...>> {};
38 
39 /// Meta-logical conjunction
40 template <typename... T>
41 struct all : Bool<true> {};
42 template <typename Head, typename... Tail>
43 struct all<Head, Tail...> : Conditional<Head::value, all<Tail...>, Bool<false>> {};
44 #endif
45 
46 // http://flamingdangerzone.com/cxx11/2012/06/01/almost-static-if.html
47 namespace dtl
48 {
49  enum class enabled {};
50 }
51 
52 // Support for Clang 3.1.
53 const dtl::enabled dummy = {};
54 
55 #ifdef __VS
56 template <typename Condition>
57 using EnableIf = typename std::enable_if<Condition::value, dtl::enabled>::type;
58 template <typename Condition>
59 using DisableIf = typename std::enable_if<!Condition::value, dtl::enabled>::type;
60 template <bool Condition>
61 using EnableIfBool = typename std::enable_if<Condition, dtl::enabled>::type;
62 #else
63 template <typename... Condition>
64 using EnableIf = typename std::enable_if<all<Condition...>::value, dtl::enabled>::type;
65 template <typename... Condition>
66 using DisableIf = typename std::enable_if<Not<any<Condition...>>::value, dtl::enabled>::type;
67 template <bool Condition>
68 using EnableIfBool = typename std::enable_if<Condition, dtl::enabled>::type;
69 #endif
70 
71 template<typename> struct Void { using type = void; };
72 
73 #ifdef __VS
74 #define has_method_struct(methodname) \
75 __if_exists(T::methodname) { \
76 template<typename T, typename SFINAE = void> \
77 struct has_##methodname : std::true_type {}; \
78 } \
79 __if_not_exists(T::methodname) { \
80 template<typename T, typename SFINAE = void> \
81 struct has_##methodname : std::false_type {}; \
82 }
83 #else
84 #define has_method_struct(methodname) \
85 template<typename T, typename SFINAE = void> \
86 struct has_##methodname : std::false_type {}; \
87 template<typename T> \
88 struct has_##methodname<T, typename Void<decltype( std::declval<T&>().methodname() )>::type> : std::true_type {};
89 #endif
90 
91 #define has_function_overload(methodname) \
92 template<typename T, typename SFINAE = void> \
93 struct has_##methodname: std::false_type {}; \
94 template<typename T> \
95 struct has_##methodname<T, typename Void<decltype( methodname(std::declval<T&>()) )>::type> : std::true_type {};
96 
100 
103 
104 //http://stackoverflow.com/questions/11251376/how-can-i-check-if-a-type-is-an-instantiation-of-a-given-class-template
105 template < template <typename...> class Template, typename T >
106 struct is_instantiation_of : std::false_type { static const bool value = false; };
107 template < template <typename...> class Template, typename... Args >
108 struct is_instantiation_of< Template, Template<Args...> > : std::true_type { static const bool value = true; };
109 
110 //template <class...> constexpr std::false_type dependent_false_v{};
111 template<class> inline constexpr bool dependent_false_v = false;
112 
113 }
#define has_function_overload(methodname)
Definition: SFINAE.h:91
carl is the main namespace for the library.
bool is_positive(const cln::cl_I &n)
Definition: operations.h:39
typename std::enable_if< Not< any< Condition... > >::value, dtl::enabled >::type DisableIf
Definition: SFINAE.h:66
typename std::enable_if< all< Condition... >::value, dtl::enabled >::type EnableIf
Definition: SFINAE.h:64
constexpr bool dependent_false_v
Definition: SFINAE.h:111
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
const dtl::enabled dummy
Definition: SFINAE.h:53
Bool<!T::value > Not
Meta-logical negation.
Definition: SFINAE.h:31
has_method_struct(normalize) has_method_struct(is_negative) has_method_struct(is_positive) has_function_overload(is_one) has_function_overload(is_zero) template< template< typename... > class Template
bool is_negative(const cln::cl_I &n)
Definition: operations.h:47
typename dependent_bool_type< B, T... >::type Bool
Definition: SFINAE.h:27
overloaded(Ts...) -> overloaded< Ts... >
typename std::conditional< If, Then, Else >::type Conditional
Definition: SFINAE.h:22
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
Definition: Interval.h:1462
typename std::enable_if< Condition, dtl::enabled >::type EnableIfBool
Definition: SFINAE.h:68
Meta-logical disjunction.
Definition: SFINAE.h:35
Meta-logical conjunction.
Definition: SFINAE.h:41
void type
Definition: SFINAE.h:71
static const bool value
Definition: SFINAE.h:106