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 
50 namespace 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.
101  typedef Future<T> type;
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>
108  struct remove_future {
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>
172  struct future_to_ref {
173  typedef T type;
174  };
175  template <typename T>
176  struct future_to_ref<Future<T>> {
177  typedef T& type;
178  };
179  template <typename T>
180  struct future_to_ref<Future<T>*> {
181  typedef T& type;
182  };
183  template <typename T>
184  struct future_to_ref<Future<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<
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  /// This defines stuff that is serializable by bitwise copy.
217  /// \warning This reports true for \c T that is an aggregate type
218  /// (struct or array) that includes pointers.
219  template <typename T>
221  static const bool value = \
222  std::is_arithmetic<T>::value || \
223  std::is_function<T>::value || \
224  is_any_function_pointer_v<T> || \
225  (std::is_standard_layout<T>::value && std::is_trivial<T>::value && !std::is_pointer<T>::value);
226 // ((std::is_class<T>::value || std::is_array<T>::value) && std::is_trivially_copyable<T>::value);
227  };
228 
229  template <typename T>
231 
232  // 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
233  namespace is_ostreammable_ns {
234 
235  template <typename To, typename From> using left_shift = decltype(std::declval<To>() << std::declval<From>());
236  template <typename To, typename From> using left_shift_in_ns_madness_operators = decltype(madness::operators::operator<<(std::declval<To>(), std::declval<From>()));
237 
238  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>>>,
239  meta::is_detected_exact<std::ostream&, left_shift_in_ns_madness_operators, std::ostream&, std::add_const_t<std::add_lvalue_reference_t<T>>>> {};
240  } // namespace is_ostreammable_ns
241 
242  /// True for types that are "serializable" to a std::ostream
243  /// \note \c operator<<(std::ostream&,const T&) must be visible via ADL or defined in namespace madness::operators
244  template <typename T>
246 
247  /// Shortcut for \c is_ostreammable<T>::value
248  template <typename T> constexpr bool is_ostreammable_v = is_ostreammable<T>::value;
249 
250  // 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
251  namespace is_istreammable_ns {
252 
253  template <typename From, typename To> using right_shift = decltype(std::declval<From>() >> std::declval<To>());
254  template <typename From, typename To> using right_shift_in_ns_madness_operators = decltype(madness::operators::operator<<(std::declval<From>(), std::declval<To>()));
255 
256  template <typename T> struct impl : public meta::disjunction<meta::is_detected_exact<std::istream&, right_shift, std::istream&, std::add_lvalue_reference_t<T>>,
257  meta::is_detected_exact<std::istream&, right_shift_in_ns_madness_operators, std::istream&, std::add_lvalue_reference_t<T>>> {};
258 
259  } // namespace is_istreammable_ns
260 
261  /// True for types that are "deserialiable" from an std::istream
262  /// \note \c operator>>(std::ostream&,T&) must be visible via ADL or defined in namespace madness::operators
263  template <typename T>
265 
266  /// Shortcut for \c is_istreammable<T>::value
267  template <typename T> constexpr bool is_istreammable_v = is_istreammable<T>::value;
268 
269  /// providing automatic support for serializing to/from std streams requires bidirectional streammability
270  template <typename T> constexpr bool is_iostreammable_v = is_istreammable_v<T> && is_ostreammable_v<T>;
271 
272  template <typename T> constexpr bool is_always_serializable =
273  std::is_arithmetic<T>::value || \
275  is_any_function_pointer_v<T> || \
276  std::is_function<T>::value;
277 
278  /// helps to detect that `T` has a member serialization method that
279  /// accepts single argument of type `Archive`
280  /// @note use in combination with madness::meta::is_detected_v
281  template<typename T, typename Archive>
282  using has_member_serialize_t = decltype(std::declval<T&>().serialize(std::declval<Archive&>()));
283 
284  /// helps to detect that `T` has a member serialization method that
285  /// accepts one argument of type `Archive` and an unsigned version
286  /// @note use in combination with madness::meta::is_detected_v
287  template<typename T, typename Archive>
288  using has_member_serialize_with_version_t = decltype(std::declval<T&>().serialize(std::declval<Archive&>(),0u));
289 
290  /// helps to detect that `T` supports nonintrusive symmetric serialization
291  /// @note use in combination with madness::meta::is_detected_v
292  template<typename T, typename Archive>
293  using has_nonmember_serialize_t = decltype(madness::archive::ArchiveSerializeImpl<Archive, T>::serialize(std::declval<Archive&>(), std::declval<T&>()));
294 
295  /// helps to detect that `T` supports nonintrusive asymmetric serialization via load
296  /// @note use in combination with madness::meta::is_detected_v
297  template<typename T, typename Archive>
298  using has_nonmember_load_t = decltype(madness::archive::ArchiveLoadImpl<Archive, T>::load(std::declval<Archive&>(), std::declval<T&>()));
299 
300  /// helps to detect that `T` supports nonintrusive asymmetric serialization via store
301  /// @note use in combination with madness::meta::is_detected_v
302  template<typename T, typename Archive>
303  using has_nonmember_store_t = decltype(madness::archive::ArchiveStoreImpl<Archive, T>::store(std::declval<Archive&>(), std::declval<T&>()));
304 
305  /// helps to detect that `T` supports nonintrusive asymmetric serialization via wrap_load
306  /// @note use in combination with madness::meta::is_detected_v
307  template<typename T, typename Archive>
308  using has_nonmember_wrap_load_t = decltype(madness::archive::ArchiveImpl<Archive, T>::wrap_load(std::declval<Archive&>(), std::declval<T&>()));
309 
310  /// helps to detect that `T` supports nonintrusive asymmetric serialization via wrap_store
311  /// @note use in combination with madness::meta::is_detected_v
312  template<typename T, typename Archive>
313  using has_nonmember_wrap_store_t = decltype(madness::archive::ArchiveImpl<Archive, T>::wrap_store(std::declval<Archive&>(), std::declval<T&>()));
314 
315  /// helps to detect that `T` supports freestanding `serialize` function
316  /// @note use in combination with madness::meta::is_detected_v
317  template<typename T, typename Archive>
318  using has_freestanding_serialize_t = decltype(serialize(std::declval<Archive&>(), std::declval<T&>()));
319 
320  /// helps to detect that `T=U*` supports freestanding `serialize` function
321  /// @note use in combination with madness::meta::is_detected_v
322  template<typename T, typename Archive, typename = std::enable_if_t<std::is_pointer_v<T>>>
323  using has_freestanding_serialize_with_size_t = decltype(serialize(std::declval<Archive&>(), std::declval<T&>(), 1u));
324 
325  /// helps to detect that `T` supports freestanding `serialize` function that accepts version
326  /// @note use in combination with madness::meta::is_detected_v
327  template<typename T, typename Archive, typename = std::enable_if_t<!std::is_pointer_v<T>>>
328  using has_freestanding_serialize_with_version_t = decltype(serialize(std::declval<Archive&>(), std::declval<T&>(), 0u));
329 
330  /// helps to detect that `T` supports freestanding `default_serialize` function
331  /// @note use in combination with madness::meta::is_detected_v
332  template<typename T, typename Archive>
333  using has_freestanding_default_serialize_t = decltype(default_serialize(std::declval<Archive&>(), std::declval<T&>()));
334 
335  /// helps to detect that `T=U*` supports freestanding `default_serialize` function
336  /// @note use in combination with madness::meta::is_detected_v
337  template<typename T, typename Archive, typename = std::enable_if_t<std::is_pointer_v<T>>>
338  using has_freestanding_default_serialize_with_size_t = decltype(default_serialize(std::declval<Archive&>(), std::declval<const T&>(), 1u));
339 
340  /// true if this is well-formed:
341  /// \code
342  /// // T t; Archive ar;
343  /// t.serialize(ar);
344  /// \endcode
345  template <typename T, typename Archive>
346  inline constexpr bool has_member_serialize_v = madness::meta::is_detected_v<madness::has_member_serialize_t,T,Archive>;
347 
348  /// true if this is well-formed:
349  /// \code
350  /// // T t; Archive ar;
351  /// t.serialize(ar, 0u);
352  /// \endcode
353  template <typename T, typename Archive>
354  inline constexpr bool has_member_serialize_with_version_v = madness::meta::is_detected_v<madness::has_member_serialize_with_version_t,T,Archive>;
355 
356  /// true if this is well-formed:
357  /// \code
358  /// // T t; Archive ar;
359  /// madness::archive::ArchiveSerializeImpl<Archive, T>::serialize(ar, t);
360  /// \endcode
361  template <typename T, typename Archive>
362  inline constexpr bool has_nonmember_serialize_v = madness::meta::is_detected_v<madness::has_nonmember_serialize_t,T,Archive>;
363 
364  /// true if this is well-formed:
365  /// \code
366  /// // T t; Archive ar;
367  /// madness::archive::ArchiveLoadImpl<Archive, T>::load(ar, t);
368  /// \endcode
369  template <typename T, typename Archive>
370  inline constexpr bool has_nonmember_load_v = madness::meta::is_detected_v<madness::has_nonmember_load_t,T,Archive>;
371 
372  /// true if this is well-formed:
373  /// \code
374  /// // T t; Archive ar;
375  /// madness::archive::ArchiveStoreImpl<Archive, T>::store(ar, t);
376  /// \endcode
377  template <typename T, typename Archive>
378  inline constexpr bool has_nonmember_store_v = madness::meta::is_detected_v<madness::has_nonmember_store_t,T,Archive>;
379 
380  template <typename T, typename Archive>
381  inline constexpr bool has_nonmember_load_and_store_v = has_nonmember_load_v<T, Archive> && has_nonmember_store_v<T, Archive>;
382 
383  /// true if this is well-formed:
384  /// \code
385  /// // T t; Archive ar;
386  /// madness::archive::ArchiveImpl<Archive, T>::wrap_load(ar, t);
387  /// \endcode
388  template <typename T, typename Archive>
389  inline constexpr bool has_nonmember_wrap_load_v = madness::meta::is_detected_v<madness::has_nonmember_wrap_load_t,T,Archive>;
390 
391  /// true if this is well-formed:
392  /// \code
393  /// // T t; Archive ar;
394  /// madness::archive::ArchiveImpl<Archive, T>::wrap_store(ar, t);
395  /// \endcode
396  template <typename T, typename Archive>
397  inline constexpr bool has_nonmember_wrap_store_v = madness::meta::is_detected_v<madness::has_nonmember_wrap_store_t,T,Archive>;
398 
399  template <typename T, typename Archive>
400  inline constexpr bool has_nonmember_wrap_load_and_store_v = has_nonmember_wrap_load_v<T, Archive> && has_nonmember_wrap_store_v<T, Archive>;
401 
402  /// true if this is well-formed:
403  /// \code
404  /// // T t; Archive ar;
405  /// serialize(ar, t);
406  /// \endcode
407  template <typename T, typename Archive>
408  inline constexpr bool has_freestanding_serialize_v = madness::meta::is_detected_v<madness::has_freestanding_serialize_t,T,Archive>;
409 
410  /// true if this is well-formed:
411  /// \code
412  /// // T t; Archive ar;
413  /// serialize(ar, &t, 1u);
414  /// \endcode
415  template <typename T, typename Archive>
416  inline constexpr bool has_freestanding_serialize_with_size_v = madness::meta::is_detected_v<madness::has_freestanding_serialize_with_size_t,T,Archive>;
417 
418  /// true if this is well-formed:
419  /// \code
420  /// // T t; Archive ar;
421  /// serialize(ar, t, 0u);
422  /// \endcode
423  template <typename T, typename Archive>
424  inline constexpr bool has_freestanding_serialize_with_version_v = madness::meta::is_detected_v<madness::has_freestanding_serialize_with_version_t,T,Archive>;
425 
426  /// true if this is well-formed:
427  /// \code
428  /// // T t; Archive ar;
429  /// default_serialize(ar, t);
430  /// \endcode
431  template <typename T, typename Archive>
432  inline constexpr bool has_freestanding_default_serialize_v = madness::meta::is_detected_v<madness::has_freestanding_default_serialize_t,T,Archive>;
433 
434  /// true if this is well-formed:
435  /// \code
436  /// // T t; Archive ar;
437  /// default_serialize(ar, &t, 1u);
438  /// \endcode
439  template <typename T, typename Archive>
440  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>;
441 
442  template <typename Archive, typename T, typename Enabler = void>
443  struct is_default_serializable_helper : public std::false_type {};
444 
445  /// \brief is \c std::true_type if \c T can be serialized to \c Archive
446  /// without specialized \c serialize() method
447  ///
448  /// For text stream-based \c Archive this is \c std::true_type if \c is_iostreammable<T>::value is true.
449  /// For other \c Archive types this is \c std::true_type if \c is_trivially_serializable<T>::value is true.
450  /// \tparam Archive an Archive type
451  /// \tparam T a type
452  template <typename Archive, typename T>
454  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;
455  };
456 
457  template <typename Archive, typename T>
459 
460  template <typename Archive, typename T>
461  inline constexpr bool is_default_serializable_v<Archive, const T> = is_default_serializable_v<Archive, T>;
462 
463  // forward declare archives to provide archive-specific overloads
464  namespace archive {
465  class BaseArchive;
466  class BaseInputArchive;
467  class BaseOutputArchive;
468  class BinaryFstreamOutputArchive;
469  class BinaryFstreamInputArchive;
470  class BufferOutputArchive;
471  class BufferInputArchive;
472  class VectorOutputArchive;
473  class VectorInputArchive;
474  class TextFstreamOutputArchive;
475  class TextFstreamInputArchive;
476  class MPIRawOutputArchive;
477  class MPIRawInputArchive;
478  class MPIOutputArchive;
479  class MPIInputArchive;
480  class ContainerRecordInputArchive;
481  class ContainerRecordOutputArchive;
482  template <class localarchiveT>
483  class ParallelOutputArchive;
484  template <class localarchiveT>
485  class ParallelInputArchive;
486  template <typename T>
487  class archive_array;
488  } // namespace archive
489 
490  /// Checks if \c T is an archive type.
491 
492  /// If \c T is an archive type, then \c is_archive will be inherited
493  /// from \c std::true_type, otherwise it is inherited from
494  /// \c std::false_type.
495  /// \tparam T The type to check.
496  /// \note define for your custom MADNESS archive type
497  template <typename T, typename Enabler = void>
498  struct is_archive;
499 
500  template <typename T>
502 
503  template <typename T>
504  inline constexpr bool is_archive_v = meta::is_detected_v<is_archive_defined_t,T>;
505 
506 
507  /// Checks if \c T is an input archive type.
508 
509  /// If \c T is an input archive type, then \c is_input_archive will be
510  /// inherited from \c std::true_type, otherwise it is inherited from
511  /// \c std::false_type.
512  /// \tparam T The type to check.
513  /// \note define for your custom MADNESS input archive type
514  template <typename T, typename Enabler = void>
516 
517  template <typename T>
519 
520  template <typename T>
521  inline constexpr bool is_input_archive_v = meta::is_detected_v<is_input_archive_defined_t, T>;
522 
523  /// Checks if \c T is an output archive type.
524 
525  /// If \c T is an output archive type, then \c is_output_archive will
526  /// be inherited from \c std::true_type, otherwise it is inherited from
527  /// \c std::false_type.
528  /// \tparam T The type to check.
529  /// \note define for your custom MADNESS output archive type
530  template <typename T, typename Enabler = void>
532 
533  template <typename T>
535 
536  template <typename T>
537  inline constexpr bool is_output_archive_v = meta::is_detected_v<is_output_archive_defined_t, T>;
538 
539  template <typename T>
540  struct is_default_serializable_helper<archive::BinaryFstreamOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
541  template <typename T>
542  struct is_default_serializable_helper<archive::BinaryFstreamInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
543  template <typename T>
544  struct is_default_serializable_helper<archive::BufferOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
545  template <typename T>
546  struct is_default_serializable_helper<archive::BufferInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
547  template <typename T>
548  struct is_default_serializable_helper<archive::VectorOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
549  template <typename T>
550  struct is_default_serializable_helper<archive::VectorInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
551  // N.B. if type can be printed but can't be read it's not serializable
552  // N.N.B. functions and function pointers will be converted to integers, hence will be always serializable
553  template <typename T>
554  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 {};
555  template <typename T>
556  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 {};
557  template <typename T>
558  struct is_default_serializable_helper<archive::MPIRawOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
559  template <typename T>
560  struct is_default_serializable_helper<archive::MPIRawInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
561  template <typename T>
562  struct is_default_serializable_helper<archive::MPIOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
563  template <typename T>
564  struct is_default_serializable_helper<archive::MPIInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
565  template <typename T>
566  struct is_default_serializable_helper<archive::ContainerRecordOutputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
567  template <typename T>
568  struct is_default_serializable_helper<archive::ContainerRecordInputArchive, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
569  template <typename T, class localarchiveT>
570  struct is_default_serializable_helper<archive::ParallelOutputArchive<localarchiveT>, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
571  template <typename T, class localarchiveT>
572  struct is_default_serializable_helper<archive::ParallelInputArchive<localarchiveT>, T, std::enable_if_t<is_trivially_serializable<T>::value>> : std::true_type {};
573  template <typename Archive, typename T>
574  struct is_default_serializable_helper<Archive, archive::archive_array<T>, std::enable_if_t<is_default_serializable_helper<Archive,T>::value>> : std::true_type {};
575 
576  template <>
577  struct is_archive<archive::BinaryFstreamOutputArchive> : std::true_type {};
578  template <>
579  struct is_archive<archive::BinaryFstreamInputArchive> : std::true_type {};
580  template <>
581  struct is_archive<archive::BufferOutputArchive> : std::true_type {};
582  template <>
583  struct is_archive<archive::BufferInputArchive> : std::true_type {};
584  template <>
585  struct is_archive<archive::VectorOutputArchive> : std::true_type {};
586  template <>
587  struct is_archive<archive::VectorInputArchive> : std::true_type {};
588  template <>
589  struct is_archive<archive::TextFstreamOutputArchive> : std::true_type {};
590  template <>
591  struct is_archive<archive::TextFstreamInputArchive> : std::true_type {};
592  template <>
593  struct is_archive<archive::MPIRawOutputArchive> : std::true_type {};
594  template <>
595  struct is_archive<archive::MPIRawInputArchive> : std::true_type {};
596  template <>
597  struct is_archive<archive::MPIOutputArchive> : std::true_type {};
598  template <>
599  struct is_archive<archive::MPIInputArchive> : std::true_type {};
600  template <>
601  struct is_archive<archive::ContainerRecordOutputArchive> : std::true_type {};
602  template <>
603  struct is_archive<archive::ContainerRecordInputArchive> : std::true_type {};
604  template <class localarchiveT>
605  struct is_archive<archive::ParallelOutputArchive<localarchiveT> > : std::true_type {};
606  template <class localarchiveT>
607  struct is_archive<archive::ParallelInputArchive<localarchiveT> > : std::true_type {};
608 
609  template <>
610  struct is_output_archive<archive::BinaryFstreamOutputArchive> : std::true_type {};
611  template <>
612  struct is_output_archive<archive::BufferOutputArchive> : std::true_type {};
613  template <>
614  struct is_output_archive<archive::VectorOutputArchive> : std::true_type {};
615  template <>
616  struct is_output_archive<archive::TextFstreamOutputArchive> : std::true_type {};
617  template <>
618  struct is_output_archive<archive::MPIRawOutputArchive> : std::true_type {};
619  template <>
620  struct is_output_archive<archive::MPIOutputArchive> : std::true_type {};
621  template <>
622  struct is_output_archive<archive::ContainerRecordOutputArchive> : std::true_type {};
623  template <class localarchiveT>
624  struct is_output_archive<archive::ParallelOutputArchive<localarchiveT> > : std::true_type {};
625 
626  template <>
627  struct is_input_archive<archive::BinaryFstreamInputArchive> : std::true_type {};
628  template <>
629  struct is_input_archive<archive::BufferInputArchive> : std::true_type {};
630  template <>
631  struct is_input_archive<archive::VectorInputArchive> : std::true_type {};
632  template <>
633  struct is_input_archive<archive::TextFstreamInputArchive> : std::true_type {};
634  template <>
635  struct is_input_archive<archive::MPIRawInputArchive> : std::true_type {};
636  template <>
637  struct is_input_archive<archive::MPIInputArchive> : std::true_type {};
638  template <>
639  struct is_input_archive<archive::ContainerRecordInputArchive> : std::true_type {};
640  template <class localarchiveT>
641  struct is_input_archive<archive::ParallelInputArchive<localarchiveT> > : std::true_type {};
642 
643  /// Evaluates to true if can serialize an object of type `T` to an object of type `Archive` using user-provided methods
644  /// \tparam Archive
645  /// \tparam T
646  template <typename Archive, typename T>
647  inline constexpr bool is_user_serializable_v = is_archive_v<Archive> && (has_member_serialize_v<T, Archive> ||
648  has_nonmember_serialize_v<T, Archive> ||
649  ((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>) ||
650  ((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>));
651 
652  template <typename Archive, typename T>
653  inline constexpr bool is_user_serializable_v<Archive, const T> = is_user_serializable_v<Archive, T>;
654 
655  /// Evaluates to true if can serialize an object of type `T` to an object of type `Archive`,
656  /// using either user-provided methods or, if `T` is default-serializable to `Archive`,
657  /// using default method for this `Archive`
658  /// \tparam Archive
659  /// \tparam T
660  template <typename Archive, typename T>
661  inline constexpr bool is_serializable_v = is_archive_v<Archive> && (is_default_serializable_v<Archive, T> ||
662  is_user_serializable_v<Archive,T>);
663 
664  template <typename Archive, typename T>
665  inline constexpr bool is_serializable_v<Archive, const T> = is_serializable_v<Archive, T>;
666 
667  template <typename Archive, typename T>
668  struct is_serializable : std::bool_constant<is_serializable_v<Archive,T>> {};
669 
670  /// \brief This trait types tests if \c Archive is a text archive
671  /// \tparam Archive an archive type
672  /// \note much be specialized for each archive
673  template <typename Archive, typename Enabler = void>
674  struct is_text_archive : std::false_type {};
675 
676  template <>
677  struct is_text_archive<archive::TextFstreamOutputArchive> : std::true_type {};
678  template <>
679  struct is_text_archive<archive::TextFstreamInputArchive> : std::true_type {};
680 
681  /// \brief \c is_text_archive_v<A> is a shorthand for \c is_text_archive<A>::value
682  /// \tparam Archive an archive type
683  template <typename Archive>
685 
686  /* Macros to make some of this stuff more readable */
687 
688  /**
689  \def REMCONST(TYPE)
690  \brief Macro to make remove_const<T> easier to use
691 
692  \def MEMFUN_RETURNT(TYPE)
693  \brief Macro to make member function type traits easier to use
694  */
695 
696 #define REMCONST(TYPE) typename std::remove_const< TYPE >::type
697 #define MEMFUN_RETURNT(MEMFUN) typename madness::detail::memfunc_traits< MEMFUN >::result_type
698 
699 } // namespace madness
700 
701 #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
std::enable_if_t< ! is_default_serializable< Archive, T >::value &&is_archive< Archive >::value, void > serialize(const Archive &ar, const T *t, unsigned int n)
Serialize (or deserialize) an array of non-fundamental stuff.
Definition: archive.h:497
std::enable_if_t< is_output_archive< Archive >::value &&is_default_serializable< Archive, T >::value &&is_function_pointer_v< T >, void > default_serialize(const Archive &ar, const T *t, unsigned int n)
Serialize an array of fundamental stuff.
Definition: archive.h:402
decltype(madness::operators::operator<<(std::declval< From >(), std::declval< To >())) right_shift_in_ns_madness_operators
Definition: type_traits.h:254
decltype(std::declval< From >() > > std::declval< To >()) right_shift
Definition: type_traits.h:253
decltype(madness::operators::operator<<(std::declval< To >(), std::declval< From >())) left_shift_in_ns_madness_operators
Definition: type_traits.h:236
decltype(std::declval< To >()<< std::declval< From >()) left_shift
Definition: type_traits.h:235
std::ostream & operator>>(std::ostream &, __x &)
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
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
constexpr bool has_nonmember_load_and_store_v
Definition: type_traits.h:381
typename future_to_ref< T >::type future_to_ref_t
Definition: type_traits.h:192
constexpr bool is_serializable_v
Definition: type_traits.h:661
typename remove_fcvr< T >::type remove_fcvr_t
Definition: type_traits.h:202
constexpr bool is_always_serializable
Definition: type_traits.h:272
decltype(madness::archive::ArchiveImpl< Archive, T >::wrap_load(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_wrap_load_t
Definition: type_traits.h:308
decltype(std::declval< T & >().serialize(std::declval< Archive & >())) has_member_serialize_t
Definition: type_traits.h:282
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:267
decltype(serialize(std::declval< Archive & >(), std::declval< T & >(), 1u)) has_freestanding_serialize_with_size_t
Definition: type_traits.h:323
constexpr bool has_nonmember_wrap_load_v
Definition: type_traits.h:389
decltype(serialize(std::declval< Archive & >(), std::declval< T & >())) has_freestanding_serialize_t
Definition: type_traits.h:318
constexpr bool is_default_serializable_v< Archive, const T >
Definition: type_traits.h:461
constexpr bool is_user_serializable_v< Archive, const T >
Definition: type_traits.h:653
constexpr bool has_member_serialize_v
Definition: type_traits.h:346
constexpr bool has_freestanding_serialize_with_size_v
Definition: type_traits.h:416
constexpr bool has_nonmember_wrap_load_and_store_v
Definition: type_traits.h:400
decltype(default_serialize(std::declval< Archive & >(), std::declval< const T & >(), 1u)) has_freestanding_default_serialize_with_size_t
Definition: type_traits.h:338
constexpr bool has_freestanding_serialize_with_version_v
Definition: type_traits.h:424
constexpr bool has_freestanding_serialize_v
Definition: type_traits.h:408
decltype(madness::archive::ArchiveSerializeImpl< Archive, T >::serialize(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_serialize_t
Definition: type_traits.h:293
constexpr bool is_iostreammable_v
providing automatic support for serializing to/from std streams requires bidirectional streammability
Definition: type_traits.h:270
constexpr bool is_user_serializable_v
Definition: type_traits.h:647
typename is_input_archive< std::remove_reference_t< std::remove_cv_t< T > >>::type is_input_archive_defined_t
Definition: type_traits.h:518
decltype(madness::archive::ArchiveLoadImpl< Archive, T >::load(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_load_t
Definition: type_traits.h:298
constexpr bool is_ostreammable_v
Shortcut for is_ostreammable<T>::value.
Definition: type_traits.h:248
typename is_archive< std::remove_reference_t< std::remove_cv_t< T > >>::type is_archive_defined_t
Definition: type_traits.h:501
typename is_output_archive< std::remove_reference_t< std::remove_cv_t< T > >>::type is_output_archive_defined_t
Definition: type_traits.h:534
constexpr bool is_default_serializable_v
Definition: type_traits.h:458
decltype(default_serialize(std::declval< Archive & >(), std::declval< T & >())) has_freestanding_default_serialize_t
Definition: type_traits.h:333
constexpr bool is_output_archive_v
Definition: type_traits.h:537
constexpr bool has_nonmember_wrap_store_v
Definition: type_traits.h:397
constexpr bool has_freestanding_default_serialize_v
Definition: type_traits.h:432
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:328
constexpr bool is_input_archive_v
Definition: type_traits.h:521
constexpr bool has_member_serialize_with_version_v
Definition: type_traits.h:354
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:303
constexpr bool has_nonmember_serialize_v
Definition: type_traits.h:362
decltype(std::declval< T & >().serialize(std::declval< Archive & >(), 0u)) has_member_serialize_with_version_t
Definition: type_traits.h:288
constexpr bool is_serializable_v< Archive, const T >
Definition: type_traits.h:665
constexpr bool has_nonmember_store_v
Definition: type_traits.h:378
constexpr bool is_archive_v
Definition: type_traits.h:504
constexpr const bool is_text_archive_v
is_text_archive_v is a shorthand for is_text_archive<A>::value
Definition: type_traits.h:684
decltype(madness::archive::ArchiveImpl< Archive, T >::wrap_store(std::declval< Archive & >(), std::declval< T & >())) has_nonmember_wrap_store_t
Definition: type_traits.h:313
constexpr bool has_nonmember_load_v
Definition: type_traits.h:370
typename remove_future< T >::type remove_future_t
C++11 version of REMFUTURE.
Definition: type_traits.h:166
constexpr bool has_freestanding_default_serialize_with_size_v
Definition: type_traits.h:440
constexpr bool is_trivially_serializable_v
Definition: type_traits.h:230
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
Default implementations of wrap_store and wrap_load.
Definition: archive.h:726
Default load of an object via serialize(ar, t).
Definition: archive.h:666
Default symmetric serialization of a non-fundamental type that has serialize method.
Definition: archive.h:554
Default store of an object via serialize(ar, t).
Definition: archive.h:611
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:498
Definition: type_traits.h:443
is std::true_type if T can be serialized to Archive without specialized serialize() method
Definition: type_traits.h:453
static constexpr bool value
Definition: type_traits.h:454
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:515
Definition: type_traits.h:257
Definition: type_traits.h:264
Definition: type_traits.h:239
Definition: type_traits.h:245
Checks if T is an output archive type.
Definition: type_traits.h:531
Definition: type_traits.h:668
This trait types tests if Archive is a text archive.
Definition: type_traits.h:674
Definition: type_traits.h:220
static const bool value
Definition: type_traits.h:221
Definition: meta.h:29
Definition: type_traits.h:197
remove_future< typename std::remove_cv< typename std::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
double u(const double x, const double expnt)
Definition: testperiodic.cc:56