SUNphi  1.0
Default.hpp
Go to the documentation of this file.
1 #ifndef _SERIALIZE_DEFAULT_HPP
2 #define _SERIALIZE_DEFAULT_HPP
3 
4 /// \file serialize/Default.hpp
5 ///
6 /// \brief Provides default for a serializer
7 
8 #include <metaprogramming/UniversalReferences.hpp>
9 #include <serialize/Base.hpp>
10 
11 namespace SUNphi
12 {
14 
15  /// Mark to print only non-default
16  [[ maybe_unused ]]
17  constexpr bool ONLY_NON_DEFAULT=
18  true;
19 
20  /// Provide a default value for a serializable reference
21  ///
22  /// Forward declaration
23  template <typename T,
24  bool>
25  class SerializableDefaultValue;
26 
27  /// Provide a default value for a serializable reference
28  template <typename T>
29  class SerializableDefaultValue<T,true>
30  {
31 
32  public:
33 
34  /// Default value stored
35  const T def;
36 
37  /// Store the default value
38  template <typename...TDef>
40  : def(forw<TDef>(def)...)
41  {
42  }
43 
44  /// Put to default
45  void putToDefault()
46  {
47  (*static_cast<Serializable<T>*>(this))()=
48  def;
49  }
50  };
51 
52  /// Provide no default value for a serializable reference
53  template <typename T>
54  class SerializableDefaultValue<T,false>
55  {
56  public:
57 
58  /// Construct doing nothing
60  {
61  }
62 
63  /// Put to default
64  void putToDefault()
65  {
66  (*static_cast<Serializable<T>*>(this))()=
67  T{};
68  }
69  };
70 }
71 
72 #endif
SerializableDefaultValue(const T={})
Construct doing nothing.
Definition: Default.hpp:59
#define DEFINE_HAS_MEMBER(TAG)
Definition: TypeTraits.hpp:581
const T def
Default value stored.
Definition: Default.hpp:35
SerializableDefaultValue(TDef &&...def)
Store the default value.
Definition: Default.hpp:39
constexpr bool ONLY_NON_DEFAULT
Mark to print only non-default.
Definition: Default.hpp:17
decltype(auto) operator+(T1 &&smet1, T2 &&smet2)
Implement smet1+smet2.
Definition: Add.hpp:87