MADNESS 0.10.1
type_traits.h
Go to the documentation of this file.
1/*
2 This file is part of MADNESS.
3
4 Copyright (C) 2007,2010 Oak Ridge National Laboratory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 For more information please contact:
21
22 Robert J. Harrison
23 Oak Ridge National Laboratory
24 One Bethel Valley Road
25 P.O. Box 2008, MS-6367
26
27 email: harrisonrj@ornl.gov
28 tel: 865-241-3937
29 fax: 865-572-0680
30*/
31
32#ifndef MADNESS_WORLD_TYPE_TRAITS_H__INCLUDED
33#define MADNESS_WORLD_TYPE_TRAITS_H__INCLUDED
34
35/// \file typestuff.h
36/// \brief type traits and templates
37
38/*
39 * N.B. this must be pure c++, usable without any context other than
40 * the current compiler + library + C++ standard.
41 * DO NOT include non-standard headers here!
42 */
43
44#include <cstddef>
45#include <cstdint>
46#include <type_traits>
47#include <iosfwd>
48#include <madness/world/meta.h>
49
50namespace madness {
51
52 namespace operators {
53 class __x {};
54 std::ostream& operator<<(std::ostream&, const __x&);
55 std::ostream& operator>>(std::ostream&, __x&);
56 } // namespace operators
57
58 // fwd decls
59 namespace archive {
60 template <typename Archive, typename T, typename Enabler = void>
61 struct ArchiveSerializeImpl;
62
63 template <class Archive, class T, typename Enabler = void>
64 struct ArchiveLoadImpl;
65
66 template <class Archive, class T, typename Enabler = void>
67 struct ArchiveStoreImpl;
68
69 template <class Archive, class T, typename Enabler = void>
70 struct ArchiveImpl;
71 }
72
73 template <typename> class Future;
74
75 /// test if a type is a future.
76
77 /// \tparam T The type to test.
78 template <typename T>
79 struct is_future : public std::false_type { };
80
81 template <typename T>
82 struct is_future< Future<T> > : public std::true_type { };
83
84 /// maps type \c T to \c Future<T>.
85
86 /// \tparam T The type to have future added.
87 template <typename T>
88 struct add_future {
89 /// Type with \c Future added.
90 typedef Future<T> type;
91 };
92
93 /// maps \c Future<T> to \c Future<T>.
94
95 /// Specialization of \c add_future<T> that properly forbids the type
96 /// \c Future< Future<T> >.
97 /// \tparam T The underlying data type.
98 template <typename T>
99 struct add_future< Future<T> > {
100 /// Type with \c Future added.
102 };
103
104 /// maps \c Future<T> to \c T.
105
106 /// \tparam T The type to have future removed; in this case, do nothing.
107 template <typename T>
109 /// Type with \c Future removed.
110 typedef T type;
111 };
112
113 /// This metafunction maps \c Future<T> to \c T.
114
115 /// \internal Future is a wrapper for T (it acts like an Identity monad), so this
116 /// unwraps T. It makes sense that the result should preserve the access traits
117 /// of the Future, i.e. const Future<T> should map to const T, etc.
118
119 /// Specialization of \c remove_future for \c Future<T>
120 /// \tparam T The type to have future removed.
121 template <typename T>
122 struct remove_future< Future<T> > {
123 /// Type with \c Future removed.
124 typedef T type;
125 };
126
127 /// Specialization of \c remove_future for \c Future<T>
128 /// \tparam T The type to have future removed.
129 template <typename T>
130 struct remove_future< const Future<T> > {
131 /// Type with \c Future removed.
132 typedef const T type;
133 };
134
135 /// Specialization of \c remove_future for \c Future<T>&
136 /// \tparam T The type to have future removed.
137 template <typename T>
138 struct remove_future< Future<T>& > {
139 /// Type with \c Future removed.
140 typedef T& type;
141 };
142
143 /// Specialization of \c remove_future for \c Future<T>&&
144 /// \tparam T The type to have future removed.
145 template <typename T>
146 struct remove_future< Future<T>&& > {
147 /// Type with \c Future removed.
148 typedef T&& type;
149 };
150
151 /// Specialization of \c remove_future for \c const \c Future<T>&
152 /// \tparam T The type to have future removed.
153 template <typename T>
154 struct remove_future< const Future<T>& > {
155 /// Type with \c Future removed.
156 typedef const T& type;
157 };
158
159 /// Macro to determine type of future (by removing wrapping \c Future template).
160
161 /// \param T The type (possibly with \c Future).
162 #define REMFUTURE(T) typename remove_future< T >::type
163
164 /// C++11 version of REMFUTURE
165 template <typename T>
167
168 /// Similar to remove_future , but future_to_ref<Future<T>> evaluates to T& ,whereas
169 /// remove_future<Future<T>> evaluates to T .
170 /// \tparam T The type to have future removed; in this case, do nothing.
171 template <typename T>
173 typedef T type;
174 };
175 template <typename T>
177 typedef T& type;
178 };
179 template <typename T>
181 typedef T& type;
182 };
183 template <typename T>
185 typedef T& type;
186 };
187 template <typename T>
188 struct future_to_ref<const Future<T>&> {
189 typedef T& type;
190 };
191 template <typename T>
193
194
195 // Remove Future, const, volatile, and reference qualifiers from the type
196 template <typename T>
197 struct remove_fcvr {
198 typedef typename remove_future<typename std::remove_cv<
199 typename std::remove_reference<T>::type>::type>::type type;
200 };
201 template <typename T>
203
204 /// is true type if \p T is a pointer to a free function
205 template <typename T, typename Enabler = void> struct is_function_pointer : public std::false_type {};
206 template <typename T> struct is_function_pointer<T, std::enable_if_t<std::is_function<typename std::remove_pointer<T>::type>::value>> : public std::true_type {};
207 template <typename T> constexpr bool is_function_pointer_v = is_function_pointer<T>::value;
208
209 // use std::is_member_function_pointer<T> if looking for is_member_function_pointer
210
211 /// is true type if \p T is a pointer to free or member function
212 template <typename T, typename Enabler = void> struct is_any_function_pointer : public std::false_type {};
213 template <typename T> struct is_any_function_pointer<T, std::enable_if_t<std::is_member_function_pointer<T>::value || is_function_pointer_v<T>>> : public std::true_type {};
214 template <typename T> constexpr bool is_any_function_pointer_v = is_any_function_pointer<T>::value;
215
216 /// trait for trivial (=bitwise) copyability of T, defaults to std::is_trivially_copyable<T> but can be specialized as needed
217 template <typename T>
218 struct is_trivially_copyable : std::is_trivially_copyable<T> {};
219
220 template <typename T>
222
223 /// This defines stuff that is serializable by bitwise copy.
224 /// \warning This reports true for \c T that is an aggregate type
225 /// (struct or array) that includes pointers.
226 template <typename T>
228 static const bool value = \
229 std::is_arithmetic<T>::value || \
230 std::is_function<T>::value || \
231 is_any_function_pointer_v<T> || \
232 (std::is_standard_layout<T>::value && std::is_trivial<T>::value && !std::is_pointer<T>::value);
233// ((std::is_class<T>::value || std::is_array<T>::value) && std::is_trivially_copyable<T>::value);
234 };
235
236 template <typename T>
238
239 // namespace hiding implementation details of is_ostreammable ... by ensuring that the detector lives in a different namespace branch than the operators we do not accidentally pick them up
240 namespace is_ostreammable_ns {
241
242 template <typename To, typename From> using left_shift = decltype(std::declval<To>() << std::declval<From>());
243 template <typename To, typename From> using left_shift_in_ns_madness_operators = decltype(madness::operators::operator<<(std::declval<To>(), std::declval<From>()));
244
245 template <typename T> struct impl : public meta::disjunction<meta::is_detected_exact<std::ostream&, left_shift, std::ostream&, std::add_const_t<std::add_lvalue_reference_t<T>>>,
246 meta::is_detected_exact<std::ostream&, left_shift_in_ns_madness_operators, std::ostream&, std::add_const_t<std::add_lvalue_reference_t<T>>>> {};
247 } // namespace is_ostreammable_ns
248
249 /// True for types that are "serializable" to a std::ostream
250 /// \note \c operator<<(std::ostream&,const T&) must be visible via ADL or defined in namespace madness::operators
251 template <typename T>
253
254 /// Shortcut for \c is_ostreammable<T>::value
255 template <typename T> constexpr bool is_ostreammable_v = is_ostreammable<T>::value;
256
257 // namespace hiding implementation details of is_istreammable ... by ensuring that the detector lives in a different namespace branch than the operators we do not accidentally pick them up
258 namespace is_istreammable_ns {
259
260 template <typename From, typename To> using right_shift = decltype(std::declval<From>() >> std::declval<To>());
261 template <typename From, typename To> using right_shift_in_ns_madness_operators = decltype(madness::operators::operator<<(std::declval<From>(), std::declval<To>()));
262
263 template <typename T> struct impl : public meta::disjunction<meta::is_detected_exact<std::istream&, right_shift, std::istream&, std::add_lvalue_reference_t<T>>,
264 meta::is_detected_exact<std::istream&, right_shift_in_ns_madness_operators, std::istream&, std::add_lvalue_reference_t<T>>> {};
265
266 } // namespace is_istreammable_ns
267
268 /// True for types that are "deserialiable" from an std::istream
269 /// \note \c operator>>(std::ostream&,T&) must be visible via ADL or defined in namespace madness::operators
270 template <typename T>
272
273 /// Shortcut for \c is_istreammable<T>::value
274 template <typename T> constexpr bool is_istreammable_v = is_istreammable<T>::value;
275
276 /// providing automatic support for serializing to/from std streams requires bidirectional streammability
277 template <typename T> constexpr bool is_iostreammable_v = is_istreammable_v<T> && is_ostreammable_v<T>;
278
279 template <typename T> constexpr bool is_always_serializable =
280 std::is_arithmetic<T>::value || \
281 std::is_same<std::nullptr_t, typename std::remove_cv<T>::type>::value || \
282 is_any_function_pointer_v<T> || \
283 std::is_function<T>::value;
284
285 /// helps to detect that `T` has a member serialization method that
286 /// accepts single argument of type `Archive`
287 /// @note use in combination with madness::meta::is_detected_v
288 template<typename T, typename Archive>
289 using has_member_serialize_t = decltype(std::declval<T&>().serialize(std::declval<Archive&>()));
290
291 /// helps to detect that `T` has a member serialization method that
292 /// accepts one argument of type `Archive` and an unsigned version
293 /// @note use in combination with madness::meta::is_detected_v
294 template<typename T, typename Archive>
295 using has_member_serialize_with_version_t = decltype(std::declval<T&>().serialize(std::declval<Archive&>(),0u));
296
297 /// helps to detect that `T` supports nonintrusive symmetric serialization
298 /// @note use in combination with madness::meta::is_detected_v
299 template<typename T, typename Archive>
300 using has_nonmember_serialize_t = decltype(madness::archive::ArchiveSerializeImpl<Archive, T>::serialize(std::declval<Archive&>(), std::declval<T&>()));
301
302 /// helps to detect that `T` supports nonintrusive asymmetric serialization via load
303 /// @note use in combination with madness::meta::is_detected_v
304 template<typename T, typename Archive>
305 using has_nonmember_load_t = decltype(madness::archive::ArchiveLoadImpl<Archive, T>::load(std::declval<Archive&>(), std::declval<T&>()));
306
307 /// helps to detect that `T` supports nonintrusive asymmetric serialization via store
308 /// @note use in combination with madness::meta::is_detected_v
309 template<typename T, typename Archive>
310 using has_nonmember_store_t = decltype(madness::archive::ArchiveStoreImpl<Archive, T>::store(std::declval<Archive&>(), std::declval<T&>()));
311
312 /// helps to detect that `T` supports nonintrusive asymmetric serialization via wrap_load
313 /// @note use in combination with madness::meta::is_detected_v
314 template<typename T, typename Archive>
315 using has_nonmember_wrap_load_t = decltype(madness::archive::ArchiveImpl<Archive, T>::wrap_load(std::declval<Archive&>(), std::declval<T&>()));
316
317 /// helps to detect that `T` supports nonintrusive asymmetric serialization via wrap_store
318 /// @note use in combination with madness::meta::is_detected_v
319 template<typename T, typename Archive>
320 using has_nonmember_wrap_store_t = decltype(madness::archive::ArchiveImpl<Archive, T>::wrap_store(std::declval<Archive&>(), std::declval<T&>()));
321
322 /// helps to detect that `T` supports freestanding `serialize` function
323 /// @note use in combination with madness::meta::is_detected_v
324 template<typename T, typename Archive>
325 using has_freestanding_serialize_t = decltype(serialize(std::declval<Archive&>(), std::declval<T&>()));
326
327 /// helps to detect that `T=U*` supports freestanding `serialize` function
328 /// @note use in combination with madness::meta::is_detected_v
329 template<typename T, typename Archive, typename = std::enable_if_t<std::is_pointer_v<T>>>
330 using has_freestanding_serialize_with_size_t = decltype(serialize(std::declval<Archive&>(), std::declval<T&>(), 1u));
331
332 /// helps to detect that `T` supports freestanding `serialize` function that accepts version
333 /// @note use in combination with madness::meta::is_detected_v
334 template<typename T, typename Archive, typename = std::enable_if_t<!std::is_pointer_v<T>>>
335 using has_freestanding_serialize_with_version_t = decltype(serialize(std::declval<Archive&>(), std::declval<T&>(), 0u));
336
337 /// helps to detect that `T` supports freestanding `default_serialize` function
338 /// @note use in combination with madness::meta::is_detected_v
339 template<typename T, typename Archive>
340 using has_freestanding_default_serialize_t = decltype(default_serialize(std::declval<Archive&>(), std::declval<T&>()));
341
342 /// helps to detect that `T=U*` supports freestanding `default_serialize` function
343 /// @note use in combination with madness::meta::is_detected_v
344 template<typename T, typename Archive, typename = std::enable_if_t<std::is_pointer_v<T>>>
345 using has_freestanding_default_serialize_with_size_t = decltype(default_serialize(std::declval<Archive&>(), std::declval<const T&>(), 1u));
346
347 /// true if this is well-formed:
348 /// \code
349 /// // T t; Archive ar;
350 /// t.serialize(ar);
351 /// \endcode
352 template <typename T, typename Archive>
353 inline constexpr bool has_member_serialize_v = madness::meta::is_detected_v<madness::has_member_serialize_t,T,Archive>;
354
355 /// true if this is well-formed:
356 /// \code
357 /// // T t; Archive ar;
358 /// t.serialize(ar, 0u);
359 /// \endcode
360 template <typename T, typename Archive>
361 inline constexpr bool has_member_serialize_with_version_v = madness::meta::is_detected_v<madness::has_member_serialize_with_version_t,T,Archive>;
362
363 /// true if this is well-formed:
364 /// \code
365 /// // T t; Archive ar;
366 /// madness::archive::ArchiveSerializeImpl<Archive, T>::serialize(ar, t);
367 /// \endcode
368 template <typename T, typename Archive>
369 inline constexpr bool has_nonmember_serialize_v = madness::meta::is_detected_v<madness::has_nonmember_serialize_t,T,Archive>;
370
371 /// true if this is well-formed:
372 /// \code
373 /// // T t; Archive ar;
374 /// madness::archive::ArchiveLoadImpl<Archive, T>::load(ar, t);
375 /// \endcode
376 template <typename T, typename Archive>
377 inline constexpr bool has_nonmember_load_v = madness::meta::is_detected_v<madness::has_nonmember_load_t,T,Archive>;
378
379 /// true if this is well-formed:
380 /// \code
381 /// // T t; Archive ar;
382 /// madness::archive::ArchiveStoreImpl<Archive, T>::store(ar, t);
383 /// \endcode
384 template <typename T, typename Archive>
385 inline constexpr bool has_nonmember_store_v = madness::meta::is_detected_v<madness::has_nonmember_store_t,T,Archive>;
386
387 template <typename T, typename Archive>
388 inline constexpr bool has_nonmember_load_and_store_v = has_nonmember_load_v<T, Archive> && has_nonmember_store_v<T, Archive>;
389
390 /// true if this is well-formed:
391 /// \code
392 /// // T t; Archive ar;
393 /// madness::archive::ArchiveImpl<Archive, T>::wrap_load(ar, t);
394 /// \endcode
395 template <typename T, typename Archive>
396 inline constexpr bool has_nonmember_wrap_load_v = madness::meta::is_detected_v<madness::has_nonmember_wrap_load_t,T,Archive>;
397
398 /// true if this is well-formed:
399 /// \code
400 /// // T t; Archive ar;
401 /// madness::archive::ArchiveImpl<Archive, T>::wrap_store(ar, t);
402 /// \endcode
403 template <typename T, typename Archive>
404 inline constexpr bool has_nonmember_wrap_store_v = madness::meta::is_detected_v<madness::has_nonmember_wrap_store_t,T,Archive>;
405
406 template <typename T, typename Archive>
407 inline constexpr bool has_nonmember_wrap_load_and_store_v = has_nonmember_wrap_load_v<T, Archive> && has_nonmember_wrap_store_v<T, Archive>;
408
409 /// true if this is well-formed:
410 /// \code
411 /// // T t; Archive ar;
412 /// serialize(ar, t);
413 /// \endcode
414 template <typename T, typename Archive>
415 inline constexpr bool has_freestanding_serialize_v = madness::meta::is_detected_v<madness::has_freestanding_serialize_t,T,Archive>;
416
417 /// true if this is well-formed:
418 /// \code
419 /// // T t; Archive ar;
420 /// serialize(ar, &t, 1u);
421 /// \endcode
422 template <typename T, typename Archive>
423 inline constexpr bool has_freestanding_serialize_with_size_v = madness::meta::is_detected_v<madness::has_freestanding_serialize_with_size_t,T,Archive>;
424
425 /// true if this is well-formed:
426 /// \code
427 /// // T t; Archive ar;
428 /// serialize(ar, t, 0u);
429 /// \endcode
430 template <typename T, typename Archive>
431 inline constexpr bool has_freestanding_serialize_with_version_v = madness::meta::is_detected_v<madness::has_freestanding_serialize_with_version_t,T,Archive>;
432
433 /// true if this is well-formed:
434 /// \code
435 /// // T t; Archive ar;
436 /// default_serialize(ar, t);
437 /// \endcode
438 template <typename T, typename Archive>
439 inline constexpr bool has_freestanding_default_serialize_v = madness::meta::is_detected_v<madness::has_freestanding_default_serialize_t,T,Archive>;
440
441 /// true if this is well-formed:
442 /// \code
443 /// // T t; Archive ar;
444 /// default_serialize(ar, &t, 1u);
445 /// \endcode
446 template <typename T, typename Archive>
447 inline constexpr bool has_freestanding_default_serialize_with_size_v = madness::meta::is_detected_v<madness::has_freestanding_default_serialize_with_size_t,T,Archive>;
448
449 template <typename Archive, typename T, typename Enabler = void>
450 struct is_default_serializable_helper : public std::false_type {};
451
452 /// \brief is \c std::true_type if \c T can be serialized to \c Archive
453 /// without specialized \c serialize() method
454 ///
455 /// For text stream-based \c Archive this is \c std::true_type if \c is_iostreammable<T>::value is true.
456 /// For other \c Archive types this is \c std::true_type if \c is_trivially_serializable<T>::value is true.
457 /// \tparam Archive an Archive type
458 /// \tparam T a type
459 template <typename Archive, typename T>
461 static constexpr bool value = is_default_serializable_helper<std::remove_cv_t<std::remove_reference_t<Archive>>,std::remove_cv_t<std::remove_reference_t<T>>>::value;
462 };
463
464 template <typename Archive, typename T>
466
467 template <typename Archive, typename T>
468 inline constexpr bool is_default_serializable_v<Archive, const T> = is_default_serializable_v<Archive, T>;
469
470 // forward declare archives to provide archive-specific overloads
471 namespace archive {
472 class BaseArchive;
473 class BaseInputArchive;
474 class BaseOutputArchive;
475 class BinaryFstreamOutputArchive;
476 class BinaryFstreamInputArchive;
477 class BufferOutputArchive;
478 class BufferInputArchive;
479 class VectorOutputArchive;
480 class VectorInputArchive;
481 class TextFstreamOutputArchive;
482 class TextFstreamInputArchive;
483 class MPIRawOutputArchive;
484 class MPIRawInputArchive;
485 class MPIOutputArchive;
486 class MPIInputArchive;
487 class ContainerRecordInputArchive;
488 class ContainerRecordOutputArchive;
489 template <class localarchiveT>
490 class ParallelOutputArchive;
491 template <class localarchiveT>
492 class ParallelInputArchive;
493 template <typename T>
494 class archive_array;
495 } // namespace archive
496
497 /// Checks if \c T is an archive type.
498
499 /// If \c T is an archive type, then \c is_archive will be inherited
500 /// from \c std::true_type, otherwise it is inherited from
501 /// \c std::false_type.
502 /// \tparam T The type to check.
503 /// \note define for your custom MADNESS archive type
504 template <typename T, typename Enabler = void>
506
507 template <typename T>
509
510 template <typename T>
511 inline constexpr bool is_archive_v = meta::is_detected_v<is_archive_defined_t,T>;
512
513
514 /// Checks if \c T is an input archive type.
515
516 /// If \c T is an input archive type, then \c is_input_archive will be
517 /// inherited from \c std::true_type, otherwise it is inherited from
518 /// \c std::false_type.
519 /// \tparam T The type to check.
520 /// \note define for your custom MADNESS input archive type
521 template <typename T, typename Enabler = void>
523
524 template <typename T>
526
527 template <typename T>
528 inline constexpr bool is_input_archive_v = meta::is_detected_v<is_input_archive_defined_t, T>;
529
530 /// Checks if \c T is an output archive type.
531
532 /// If \c T is an output archive type, then \c is_output_archive will
533 /// be inherited from \c std::true_type, otherwise it is inherited from
534 /// \c std::false_type.
535 /// \tparam T The type to check.
536 /// \note define for your custom MADNESS output archive type
537 template <typename T, typename Enabler = void>
539
540 template <typename T>
542
543 template <typename T>
544 inline constexpr bool is_output_archive_v = meta::is_detected_v<is_output_archive_defined_t, T>;
545
546 template <typename T>
547 struct is_default_serializable_helper<archive::BinaryFstreamOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
548 template <typename T>
549 struct is_default_serializable_helper<archive::BinaryFstreamInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
550 template <typename T>
551 struct is_default_serializable_helper<archive::BufferOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
552 template <typename T>
553 struct is_default_serializable_helper<archive::BufferInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
554 template <typename T>
555 struct is_default_serializable_helper<archive::VectorOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
556 template <typename T>
557 struct is_default_serializable_helper<archive::VectorInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
558 // N.B. if type can be printed but can't be read it's not serializable
559 // N.N.B. functions and function pointers will be converted to integers, hence will be always serializable
560 template <typename T>
561 struct is_default_serializable_helper<archive::TextFstreamOutputArchive, T, std::enable_if_t<is_iostreammable_v<T> || std::is_function_v<T> || is_any_function_pointer_v<T>>> : std::true_type {};
562 template <typename T>
563 struct is_default_serializable_helper<archive::TextFstreamInputArchive, T, std::enable_if_t<is_iostreammable_v<T> || is_any_function_pointer_v<T>>> : std::true_type {};
564 template <typename T>
565 struct is_default_serializable_helper<archive::MPIRawOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
566 template <typename T>
567 struct is_default_serializable_helper<archive::MPIRawInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
568 template <typename T>
569 struct is_default_serializable_helper<archive::MPIOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
570 template <typename T>
571 struct is_default_serializable_helper<archive::MPIInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
572 template <typename T>
573 struct is_default_serializable_helper<archive::ContainerRecordOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
574 template <typename T>
575 struct is_default_serializable_helper<archive::ContainerRecordInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
576 template <typename T, class localarchiveT>
577 struct is_default_serializable_helper<archive::ParallelOutputArchive<localarchiveT>, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
578 template <typename T, class localarchiveT>
579 struct is_default_serializable_helper<archive::ParallelInputArchive<localarchiveT>, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
580 template <typename Archive, typename T>
581 struct is_default_serializable_helper<Archive, archive::archive_array<T>, std::enable_if_t<is_default_serializable_helper<Archive,T>::value>> : std::true_type {};
582
583 template <>
584 struct is_archive<archive::BinaryFstreamOutputArchive> : std::true_type {};
585 template <>
586 struct is_archive<archive::BinaryFstreamInputArchive> : std::true_type {};
587 template <>
588 struct is_archive<archive::BufferOutputArchive> : std::true_type {};
589 template <>
590 struct is_archive<archive::BufferInputArchive> : std::true_type {};
591 template <>
592 struct is_archive<archive::VectorOutputArchive> : std::true_type {};
593 template <>
594 struct is_archive<archive::VectorInputArchive> : std::true_type {};
595 template <>
596 struct is_archive<archive::TextFstreamOutputArchive> : std::true_type {};
597 template <>
598 struct is_archive<archive::TextFstreamInputArchive> : std::true_type {};
599 template <>
600 struct is_archive<archive::MPIRawOutputArchive> : std::true_type {};
601 template <>
602 struct is_archive<archive::MPIRawInputArchive> : std::true_type {};
603 template <>
604 struct is_archive<archive::MPIOutputArchive> : std::true_type {};
605 template <>
606 struct is_archive<archive::MPIInputArchive> : std::true_type {};
607 template <>
608 struct is_archive<archive::ContainerRecordOutputArchive> : std::true_type {};
609 template <>
610 struct is_archive<archive::ContainerRecordInputArchive> : std::true_type {};
611 template <class localarchiveT>
612 struct is_archive<archive::ParallelOutputArchive<localarchiveT> > : std::true_type {};
613 template <class localarchiveT>
614 struct is_archive<archive::ParallelInputArchive<localarchiveT> > : std::true_type {};
615
616 template <>
617 struct is_output_archive<archive::BinaryFstreamOutputArchive> : std::true_type {};
618 template <>
619 struct is_output_archive<archive::BufferOutputArchive> : std::true_type {};
620 template <>
621 struct is_output_archive<archive::VectorOutputArchive> : std::true_type {};
622 template <>
623 struct is_output_archive<archive::TextFstreamOutputArchive> : std::true_type {};
624 template <>
625 struct is_output_archive<archive::MPIRawOutputArchive> : std::true_type {};
626 template <>
627 struct is_output_archive<archive::MPIOutputArchive> : std::true_type {};
628 template <>
629 struct is_output_archive<archive::ContainerRecordOutputArchive> : std::true_type {};
630 template <class localarchiveT>
631 struct is_output_archive<archive::ParallelOutputArchive<localarchiveT> > : std::true_type {};
632
633 template <>
634 struct is_input_archive<archive::BinaryFstreamInputArchive> : std::true_type {};
635 template <>
636 struct is_input_archive<archive::BufferInputArchive> : std::true_type {};
637 template <>
638 struct is_input_archive<archive::VectorInputArchive> : std::true_type {};
639 template <>
640 struct is_input_archive<archive::TextFstreamInputArchive> : std::true_type {};
641 template <>
642 struct is_input_archive<archive::MPIRawInputArchive> : std::true_type {};
643 template <>
644 struct is_input_archive<archive::MPIInputArchive> : std::true_type {};
645 template <>
646 struct is_input_archive<archive::ContainerRecordInputArchive> : std::true_type {};
647 template <class localarchiveT>
648 struct is_input_archive<archive::ParallelInputArchive<localarchiveT> > : std::true_type {};
649
650 /// Evaluates to true if can serialize an object of type `T` to an object of type `Archive` using user-provided methods
651 /// \tparam Archive
652 /// \tparam T
653 template <typename Archive, typename T>
654 inline constexpr bool is_user_serializable_v = is_archive_v<Archive> && (has_member_serialize_v<T, Archive> ||
655 has_nonmember_serialize_v<T, Archive> ||
656 ((has_nonmember_load_v<T, Archive> || has_nonmember_wrap_load_v<T, Archive>) && is_input_archive_v<Archive> && !has_freestanding_default_serialize_v<T, Archive>) ||
657 ((has_nonmember_store_v<T, Archive> || has_nonmember_wrap_store_v<T, Archive>) && is_output_archive_v<Archive> && !has_freestanding_default_serialize_v<T, Archive>));
658
659 template <typename Archive, typename T>
660 inline constexpr bool is_user_serializable_v<Archive, const T> = is_user_serializable_v<Archive, T>;
661
662 /// Evaluates to true if can serialize an object of type `T` to an object of type `Archive`,
663 /// using either user-provided methods or, if `T` is default-serializable to `Archive`,
664 /// using default method for this `Archive`
665 /// \tparam Archive
666 /// \tparam T
667 template <typename Archive, typename T>
668 inline constexpr bool is_serializable_v = is_archive_v<Archive> && (is_default_serializable_v<Archive, T> ||
669 is_user_serializable_v<Archive,T>);
670
671 template <typename Archive, typename T>
672 inline constexpr bool is_serializable_v<Archive, const T> = is_serializable_v<Archive, T>;
673
674 template <typename Archive, typename T>
675 struct is_serializable : std::bool_constant<is_serializable_v<Archive,T>> {};
676
677 /// \brief This trait types tests if \c Archive is a text archive
678 /// \tparam Archive an archive type
679 /// \note much be specialized for each archive
680 template <typename Archive, typename Enabler = void>
681 struct is_text_archive : std::false_type {};
682
683 template <>
684 struct is_text_archive<archive::TextFstreamOutputArchive> : std::true_type {};
685 template <>
686 struct is_text_archive<archive::TextFstreamInputArchive> : std::true_type {};
687
688 /// \brief \c is_text_archive_v<A> is a shorthand for \c is_text_archive<A>::value
689 /// \tparam Archive an archive type
690 template <typename Archive>
692
693 /* Macros to make some of this stuff more readable */
694
695 /**
696 \def REMCONST(TYPE)
697 \brief Macro to make remove_const<T> easier to use
698
699 \def MEMFUN_RETURNT(TYPE)
700 \brief Macro to make member function type traits easier to use
701 */
702
703#define REMCONST(TYPE) typename std::remove_const< TYPE >::type
704#define MEMFUN_RETURNT(MEMFUN) typename madness::detail::memfunc_traits< MEMFUN >::result_type
705
706} // namespace madness
707
708#endif // MADNESS_WORLD_TYPE_TRAITS_H__INCLUDED
A future is a possibly yet unevaluated value.
Definition future.h:373
Definition type_traits.h:53
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
static double u(double r, double c)
Definition he.cc:20
decltype(madness::operators::operator<<(std::declval< From >(), std::declval< To >())) right_shift_in_ns_madness_operators
Definition type_traits.h:261
decltype(std::declval< From >() > > std::declval< To >()) right_shift
Definition type_traits.h:260
decltype(madness::operators::operator<<(std::declval< To >(), std::declval< From >())) left_shift_in_ns_madness_operators
Definition type_traits.h:243
decltype(std::declval< To >()<< std::declval< From >()) left_shift
Definition type_traits.h:242
std::ostream & operator<<(std::ostream &s, const std::array< T, N > &a)
Output std::array to stream for human consumption.
Definition array_addons.h:59
std::ostream & operator>>(std::ostream &, __x &)
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
constexpr bool has_nonmember_load_and_store_v
Definition type_traits.h:388
typename future_to_ref< T >::type future_to_ref_t
Definition type_traits.h:192
constexpr bool is_serializable_v
Definition type_traits.h:668
typename remove_fcvr< T >::type remove_fcvr_t
Definition type_traits.h:202
constexpr bool is_always_serializable
Definition type_traits.h:279
decltype(madness::archive::ArchiveImpl< Archive, T >::wrap_load(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_wrap_load_t
Definition type_traits.h:315
decltype(std::declval< T & >().serialize(std::declval< Archive & >())) has_member_serialize_t
Definition type_traits.h:289
constexpr bool is_function_pointer_v
Definition type_traits.h:207
constexpr bool is_istreammable_v
Shortcut for is_istreammable<T>::value.
Definition type_traits.h:274
decltype(serialize(std::declval< Archive & >(), std::declval< T & >(), 1u)) has_freestanding_serialize_with_size_t
Definition type_traits.h:330
constexpr bool has_nonmember_wrap_load_v
Definition type_traits.h:396
decltype(serialize(std::declval< Archive & >(), std::declval< T & >())) has_freestanding_serialize_t
Definition type_traits.h:325
constexpr bool is_default_serializable_v< Archive, const T >
Definition type_traits.h:468
constexpr bool is_user_serializable_v< Archive, const T >
Definition type_traits.h:660
constexpr bool has_member_serialize_v
Definition type_traits.h:353
constexpr bool has_freestanding_serialize_with_size_v
Definition type_traits.h:423
constexpr bool has_nonmember_wrap_load_and_store_v
Definition type_traits.h:407
decltype(default_serialize(std::declval< Archive & >(), std::declval< const T & >(), 1u)) has_freestanding_default_serialize_with_size_t
Definition type_traits.h:345
constexpr bool has_freestanding_serialize_with_version_v
Definition type_traits.h:431
constexpr bool has_freestanding_serialize_v
Definition type_traits.h:415
decltype(madness::archive::ArchiveSerializeImpl< Archive, T >::serialize(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_serialize_t
Definition type_traits.h:300
constexpr bool is_iostreammable_v
providing automatic support for serializing to/from std streams requires bidirectional streammability
Definition type_traits.h:277
constexpr bool is_user_serializable_v
Definition type_traits.h:654
typename is_input_archive< std::remove_reference_t< std::remove_cv_t< T > > >::type is_input_archive_defined_t
Definition type_traits.h:525
decltype(madness::archive::ArchiveLoadImpl< Archive, T >::load(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_load_t
Definition type_traits.h:305
constexpr bool is_ostreammable_v
Shortcut for is_ostreammable<T>::value.
Definition type_traits.h:255
typename is_archive< std::remove_reference_t< std::remove_cv_t< T > > >::type is_archive_defined_t
Definition type_traits.h:508
typename is_output_archive< std::remove_reference_t< std::remove_cv_t< T > > >::type is_output_archive_defined_t
Definition type_traits.h:541
constexpr bool is_default_serializable_v
Definition type_traits.h:465
decltype(default_serialize(std::declval< Archive & >(), std::declval< T & >())) has_freestanding_default_serialize_t
Definition type_traits.h:340
constexpr bool is_output_archive_v
Definition type_traits.h:544
constexpr bool has_nonmember_wrap_store_v
Definition type_traits.h:404
constexpr bool has_freestanding_default_serialize_v
Definition type_traits.h:439
constexpr bool is_any_function_pointer_v
Definition type_traits.h:214
decltype(serialize(std::declval< Archive & >(), std::declval< T & >(), 0u)) has_freestanding_serialize_with_version_t
Definition type_traits.h:335
constexpr bool is_input_archive_v
Definition type_traits.h:528
constexpr bool has_member_serialize_with_version_v
Definition type_traits.h:361
std::string type(const PairType &n)
Definition PNOParameters.h:18
decltype(madness::archive::ArchiveStoreImpl< Archive, T >::store(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_store_t
Definition type_traits.h:310
constexpr bool has_nonmember_serialize_v
Definition type_traits.h:369
decltype(std::declval< T & >().serialize(std::declval< Archive & >(), 0u)) has_member_serialize_with_version_t
Definition type_traits.h:295
constexpr bool is_serializable_v< Archive, const T >
Definition type_traits.h:672
constexpr bool has_nonmember_store_v
Definition type_traits.h:385
constexpr bool is_archive_v
Definition type_traits.h:511
constexpr const bool is_text_archive_v
is_text_archive_v is a shorthand for is_text_archive<A>::value
Definition type_traits.h:691
decltype(madness::archive::ArchiveImpl< Archive, T >::wrap_store(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_wrap_store_t
Definition type_traits.h:320
constexpr bool has_nonmember_load_v
Definition type_traits.h:377
typename remove_future< T >::type remove_future_t
C++11 version of REMFUTURE.
Definition type_traits.h:166
constexpr bool is_trivially_copyable_v
Definition type_traits.h:221
constexpr bool has_freestanding_default_serialize_with_size_v
Definition type_traits.h:447
constexpr bool is_trivially_serializable_v
Definition type_traits.h:237
Definition mraimpl.h:50
Future< T > type
Type with Future added.
Definition type_traits.h:101
maps type T to Future<T>.
Definition type_traits.h:88
Future< T > type
Type with Future added.
Definition type_traits.h:90
static const Archive & wrap_load(const Archive &ar, const T &t)
Load an object sandwiched between its preamble and postamble.
Definition archive.h:747
static const Archive & wrap_store(const Archive &ar, const T &t)
Store an object sandwiched between its preamble and postamble.
Definition archive.h:733
static void load(const A &ar, const U &t)
Load an object.
Definition archive.h:678
static void serialize(const Archive &ar, T &t)
Serializes the type.
Definition archive.h:560
static std::enable_if_t< is_output_archive_v< A > &&!std::is_function< U >::value &&(has_member_serialize_v< U, A >||has_nonmember_serialize_v< U, A >||has_freestanding_serialize_v< U, A >||has_freestanding_default_serialize_v< U, A >), void > store(const A &ar, const U &t)
Definition archive.h:621
T & type
Definition type_traits.h:177
T & type
Definition type_traits.h:181
T & type
Definition type_traits.h:185
T & type
Definition type_traits.h:189
Definition type_traits.h:172
T type
Definition type_traits.h:173
is true type if T is a pointer to free or member function
Definition type_traits.h:212
Checks if T is an archive type.
Definition type_traits.h:505
Definition type_traits.h:450
is std::true_type if T can be serialized to Archive without specialized serialize() method
Definition type_traits.h:460
static constexpr bool value
Definition type_traits.h:461
is true type if T is a pointer to a free function
Definition type_traits.h:205
test if a type is a future.
Definition type_traits.h:79
Checks if T is an input archive type.
Definition type_traits.h:522
Definition type_traits.h:264
Definition type_traits.h:271
Definition type_traits.h:246
Definition type_traits.h:252
Checks if T is an output archive type.
Definition type_traits.h:538
Definition type_traits.h:675
This trait types tests if Archive is a text archive.
Definition type_traits.h:681
trait for trivial (=bitwise) copyability of T, defaults to std::is_trivially_copyable<T> but can be s...
Definition type_traits.h:218
Definition type_traits.h:227
static const bool value
Definition type_traits.h:228
Definition meta.h:29
Definition type_traits.h:197
remove_future< typenamestd::remove_cv< typenamestd::remove_reference< T >::type >::type >::type type
Definition type_traits.h:199
T type
Type with Future removed.
Definition type_traits.h:124
T & type
Type with Future removed.
Definition type_traits.h:140
T && type
Type with Future removed.
Definition type_traits.h:148
const T type
Type with Future removed.
Definition type_traits.h:132
const T & type
Type with Future removed.
Definition type_traits.h:156
maps Future<T> to T.
Definition type_traits.h:108
T type
Type with Future removed.
Definition type_traits.h:110