MADNESS  0.10.1
meta.h
Go to the documentation of this file.
1 /*
2  * meta.h
3  *
4  * Created on: Apr 15, 2017
5  * Author: evaleev
6  */
7 
8 #ifndef SRC_MADNESS_WORLD_META_H_
9 #define SRC_MADNESS_WORLD_META_H_
10 
11 #include <type_traits>
12 
13 namespace madness {
14 namespace meta { // to make it easier importing another MP library
15 
16 ///////////////////////////////////////////////////////////////////////////////
17 
18 // import some existing C++17 features, or implement them
19 // TODO remove when it is possible to use CUDA/NVCC with C++17
20 # if __cplusplus <= 201402L
21 
22 template<typename... Ts>
23 struct make_void {
24  using type = void;
25 };
26 template<typename... Ts>
27 using void_t = typename make_void<Ts...>::type;
28 
29 template<class...> struct disjunction : std::false_type { };
30 template<class B1> struct disjunction<B1> : B1 { };
31 template<class B1, class... Bn>
32 struct disjunction<B1, Bn...>
33  : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> { };
34 
35 template<class... B>
36 inline constexpr bool disjunction_v = disjunction<B...>::value;
37 
38 template<class...> struct conjunction : std::true_type { };
39 template<class B1> struct conjunction<B1> : B1 { };
40 template<class B1, class... Bn>
41 struct conjunction<B1, Bn...>
42  : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
43 
44 template<class... B>
45 inline constexpr bool conjunction_v = conjunction<B...>::value;
46 
47 template< class T >
48 inline constexpr bool is_function_v = std::is_function<T>::value;
49 
50 template< class T >
51 inline constexpr bool is_member_function_pointer_v = std::is_member_function_pointer<T>::value;
52 
53 # else
54 
55 using std::void_t;
56 using std::disjunction;
57 using std::disjunction_v;
58 using std::conjunction;
59 using std::conjunction_v;
60 using std::is_function_v;
62 
63 #endif // C++17 features
64 
65 
66 ///////////////////////////////////////////////////////////////////////////////
67 
68 template <typename... P>
69 struct typelist {};
70 
71 ///////////////////////////////////////////////////////////////////////////////
72 
73 template <typename... Ts>
74 struct last_type {};
75 
76 template <typename T0>
77 struct last_type<T0> {
78  typedef T0 type;
79 };
80 
81 template <typename T0, typename T1, typename... Ts>
82 struct last_type<T0, T1, Ts...> : last_type<T1, Ts...> {};
83 
84 ///////////////////////////////////////////////////////////////////////////////
85 
86 template <template <typename...> class MetaFn, typename CurrentTypelist,
87  typename... RestOfTypes>
89 
90 template <template <typename...> class MetaFn, typename... UpToT, typename T,
91  typename... Rest>
92 struct drop_last_arg_and_apply_impl<MetaFn, typelist<UpToT...>, T, Rest...> {
93  using type =
94  typename drop_last_arg_and_apply_impl<MetaFn, typelist<UpToT..., T>,
95  Rest...>::type;
96 };
97 
98 template <template <typename...> class MetaFn, typename... UpToLast,
99  typename Last>
100 struct drop_last_arg_and_apply_impl<MetaFn, typelist<UpToLast...>, Last> {
101  using type = MetaFn<UpToLast...>;
102 };
103 
104 template <template <typename...> class MetaFn, typename... Args>
106  using type =
108 };
109 
110 ///////////////////////////////////////////////////////////////////////////////
111 
112 template <template <typename...> class MetaFn, typename Callable,
113  typename CurrentTypelist, typename... RestOfTypes>
115 
116 template <template <typename...> class MetaFn, typename Callable,
117  typename... UpToT, typename T, typename... Rest>
119  typelist<UpToT...>, T, Rest...> {
121  MetaFn, Callable, typelist<UpToT..., T>, Rest...>::type;
122 };
123 
124 template <template <typename...> class MetaFn, typename Callable,
125  typename... UpToLast, typename Last>
127  typelist<UpToLast...>, Last> {
128  using type = MetaFn<Callable(UpToLast...)>;
129 };
130 
131 template <template <typename...> class MetaFn, typename Callable,
132  typename... Args>
134  using type =
135  typename drop_last_arg_and_apply_callable_impl<MetaFn, Callable,
136  typelist<>, Args...>::type;
137 };
138 
139 ///////////////////////////////////////////////////////////////////////////////
140 
141 // nonesuch struct from Library Fundamentals V2, source from https://en.cppreference.com/w/cpp/experimental/nonesuch
142 
143 struct nonesuch {
144  ~nonesuch() = delete;
145  nonesuch(nonesuch const&) = delete;
146  void operator=(nonesuch const&) = delete;
147 };
148 
149 // is_detected family from Library Fundamentals V2, source from https://en.cppreference.com/w/cpp/experimental/is_detected
150 
151 namespace detail {
152 
153 template <class Default, class Enabler, template <class...> class Op,
154  class... Args>
155 struct detector {
156  using value_t = std::false_type;
157  using type = Default;
158 };
159 
160 template <class Default, template <class...> class Op, class... Args>
161 struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
162  using value_t = std::true_type;
163  using type = Op<Args...>;
164 };
165 
166 } // namespace detail
167 
168 template <template<class...> class Op, class... Args>
169 using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
170 
171 template <template<class...> class Op, class... Args>
172 using detected_t = typename detail::detector<nonesuch, void, Op, Args...>::type;
173 
174 template <class Default, template<class...> class Op, class... Args>
175 using detected_or = detail::detector<Default, void, Op, Args...>;
176 
177 template< template<class...> class Op, class... Args >
178 constexpr bool is_detected_v = is_detected<Op, Args...>::value;
179 
180 template< class Default, template<class...> class Op, class... Args >
181 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
182 
183 template <class Expected, template<class...> class Op, class... Args>
184 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
185 
186 template <class Expected, template<class...> class Op, class... Args>
187 constexpr bool is_detected_exact_v = is_detected_exact<Expected, Op, Args...>::value;
188 
189 template <class To, template<class...> class Op, class... Args>
190 using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>;
191 
192 template <class To, template<class...> class Op, class... Args>
193 constexpr bool is_detected_convertible_v = is_detected_convertible<To, Op, Args...>::value;
194 
195 } // namespace meta
196 } // namespace madness
197 
198 #endif /* SRC_MADNESS_WORLD_META_H_ */
Definition: test_ar.cc:141
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
constexpr bool disjunction_v
Definition: meta.h:36
constexpr bool is_detected_v
Definition: meta.h:178
constexpr bool is_detected_exact_v
Definition: meta.h:187
typename detail::detector< nonesuch, void, Op, Args... >::type detected_t
Definition: meta.h:172
constexpr bool conjunction_v
Definition: meta.h:45
typename detail::detector< nonesuch, void, Op, Args... >::value_t is_detected
Definition: meta.h:169
typename make_void< Ts... >::type void_t
Definition: meta.h:27
constexpr bool is_detected_convertible_v
Definition: meta.h:193
constexpr bool is_member_function_pointer_v
Definition: meta.h:51
std::is_convertible< detected_t< Op, Args... >, To > is_detected_convertible
Definition: meta.h:190
std::is_same< Expected, detected_t< Op, Args... > > is_detected_exact
Definition: meta.h:184
constexpr bool is_function_v
Definition: meta.h:48
typename detected_or< Default, Op, Args... >::type detected_or_t
Definition: meta.h:181
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
std::string type(const PairType &n)
Definition: PNOParameters.h:18
Definition: meta.h:38
Definition: meta.h:155
Default type
Definition: meta.h:157
std::false_type value_t
Definition: meta.h:156
Definition: meta.h:29
typename drop_last_arg_and_apply_callable_impl< MetaFn, Callable, typelist< UpToT..., T >, Rest... >::type type
Definition: meta.h:121
typename drop_last_arg_and_apply_callable_impl< MetaFn, Callable, typelist<>, Args... >::type type
Definition: meta.h:136
typename drop_last_arg_and_apply_impl< MetaFn, typelist< UpToT..., T >, Rest... >::type type
Definition: meta.h:95
typename drop_last_arg_and_apply_impl< MetaFn, typelist<>, Args... >::type type
Definition: meta.h:107
T0 type
Definition: meta.h:78
Definition: meta.h:74
Definition: meta.h:23
void type
Definition: meta.h:24
Definition: meta.h:143
void operator=(nonesuch const &)=delete
nonesuch(nonesuch const &)=delete
Definition: meta.h:69
int P
Definition: test_binsorter.cc:9