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
13namespace madness {
14namespace 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
22template<typename... Ts>
23struct make_void {
24 using type = void;
25};
26template<typename... Ts>
27using void_t = typename make_void<Ts...>::type;
28
29template<class...> struct disjunction : std::false_type { };
30template<class B1> struct disjunction<B1> : B1 { };
31template<class B1, class... Bn>
32struct disjunction<B1, Bn...>
33 : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> { };
34
35template<class... B>
36inline constexpr bool disjunction_v = disjunction<B...>::value;
37
38template<class...> struct conjunction : std::true_type { };
39template<class B1> struct conjunction<B1> : B1 { };
40template<class B1, class... Bn>
41struct conjunction<B1, Bn...>
42 : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
43
44template<class... B>
45inline constexpr bool conjunction_v = conjunction<B...>::value;
46
47template< class T >
48inline constexpr bool is_function_v = std::is_function<T>::value;
49
50template< class T >
51inline constexpr bool is_member_function_pointer_v = std::is_member_function_pointer<T>::value;
52
53# else
54
55using std::void_t;
56using std::disjunction;
57using std::disjunction_v;
58using std::conjunction;
59using std::conjunction_v;
60using std::is_function_v;
61using std::is_member_function_pointer_v;
62
63#endif // C++17 features
64
65
66///////////////////////////////////////////////////////////////////////////////
67
68template <typename... P>
69struct typelist {};
70
71///////////////////////////////////////////////////////////////////////////////
72
73template <typename... Ts>
74struct last_type {};
75
76template <typename T0>
77struct last_type<T0> {
78 typedef T0 type;
79};
80
81template <typename T0, typename T1, typename... Ts>
82struct last_type<T0, T1, Ts...> : last_type<T1, Ts...> {};
83
84///////////////////////////////////////////////////////////////////////////////
85
86template <template <typename...> class MetaFn, typename CurrentTypelist,
87 typename... RestOfTypes>
89
90template <template <typename...> class MetaFn, typename... UpToT, typename T,
91 typename... Rest>
92struct 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
98template <template <typename...> class MetaFn, typename... UpToLast,
99 typename Last>
100struct drop_last_arg_and_apply_impl<MetaFn, typelist<UpToLast...>, Last> {
101 using type = MetaFn<UpToLast...>;
102};
103
104template <template <typename...> class MetaFn, typename... Args>
109
110///////////////////////////////////////////////////////////////////////////////
111
112template <template <typename...> class MetaFn, typename Callable,
113 typename CurrentTypelist, typename... RestOfTypes>
115
116template <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
124template <template <typename...> class MetaFn, typename Callable,
125 typename... UpToLast, typename Last>
127 typelist<UpToLast...>, Last> {
128 using type = MetaFn<Callable(UpToLast...)>;
129};
130
131template <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
143struct 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
151namespace detail {
152
153template <class Default, class Enabler, template <class...> class Op,
154 class... Args>
155struct detector {
156 using value_t = std::false_type;
157 using type = Default;
158};
159
160template <class Default, template <class...> class Op, class... Args>
161struct 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
168template <template<class...> class Op, class... Args>
169using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
170
171template <template<class...> class Op, class... Args>
172using detected_t = typename detail::detector<nonesuch, void, Op, Args...>::type;
173
174template <class Default, template<class...> class Op, class... Args>
175using detected_or = detail::detector<Default, void, Op, Args...>;
176
177template< template<class...> class Op, class... Args >
178constexpr bool is_detected_v = is_detected<Op, Args...>::value;
179
180template< class Default, template<class...> class Op, class... Args >
181using detected_or_t = typename detected_or<Default, Op, Args...>::type;
182
183template <class Expected, template<class...> class Op, class... Args>
184using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
185
186template <class Expected, template<class...> class Op, class... Args>
187constexpr bool is_detected_exact_v = is_detected_exact<Expected, Op, Args...>::value;
188
189template <class To, template<class...> class Op, class... Args>
190using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>;
191
192template <class To, template<class...> class Op, class... Args>
193constexpr 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
Namespace for all elements and tools of MADNESS.
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