traits.hpp(3) Library Functions Manual traits.hpp(3)

# [NAME](#NAME)

traits.hpp - Internal type trait support.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;type\_traits&gt;  
#include &lt;typeindex&gt;  
#include 'cereal/macros.hpp'  
#include 'cereal/access.hpp'

## [Classes](#Classes)

struct **cereal::traits::detail::delay\_static\_assert&lt; T &gt;**  
Used to delay a static\_assert until template instantiation. struct **cereal::traits::detail::meta\_bool\_and&lt; H, T &gt;**  
struct **cereal::traits::detail::meta\_bool\_and&lt; B &gt;**  
struct **cereal::traits::detail::meta\_bool\_or&lt; H, T &gt;**  
struct **cereal::traits::detail::meta\_bool\_or&lt; B &gt;**  
struct **cereal::traits::detail::EnableIfHelper&lt; Conditions &gt;**  
struct **cereal::traits::detail::DisableIfHelper&lt; Conditions &gt;**  
struct **cereal::traits::detail::get\_output\_from\_input&lt; InputArchive &gt;**  
struct **cereal::traits::detail::get\_input\_from\_output&lt; OutputArchive &gt;**  
struct **cereal::traits::has\_member\_save&lt; T, A &gt;**  
struct **cereal::traits::has\_member\_versioned\_save&lt; T, A &gt;**  
struct **cereal::traits::detail::is\_string&lt; class &gt;**  
struct **cereal::traits::detail::is\_string&lt; std::basic\_string&lt; CharT, Traits, Alloc &gt; &gt;**  
struct **cereal::traits::is\_minimal\_type&lt; T &gt;**  
struct **cereal::traits::detail::NoConvertBase**  
Used to help strip away conversion wrappers. struct **cereal::traits::detail::NoConvertConstRef&lt; Source &gt;**  
A struct that prevents implicit conversion. struct **cereal::traits::detail::NoConvertRef&lt; Source &gt;**  
A struct that prevents implicit conversion. struct **cereal::traits::detail::AnyConvert**  
A type that can implicitly convert to anything else. struct **cereal::traits::detail::has\_member\_load\_and\_construct\_impl&lt; T, A &gt;**  
struct **cereal::traits::detail::has\_member\_versioned\_load\_and\_construct\_impl&lt; T, A &gt;**  
struct **cereal::traits::has\_member\_load\_and\_construct&lt; T, A &gt;**  
Member load and construct check. struct **cereal::traits::has\_member\_versioned\_load\_and\_construct&lt; T, A &gt;**  
Member load and construct check (versioned). struct **cereal::traits::has\_load\_and\_construct&lt; T, A &gt;**  
Non member load and construct check. struct **cereal::traits::has\_member\_split&lt; T, InputArchive, OutputArchive &gt;**  
struct **cereal::traits::has\_non\_member\_split&lt; T, InputArchive, OutputArchive &gt;**  
struct **cereal::traits::has\_invalid\_output\_versioning&lt; T, OutputArchive &gt;**  
struct **cereal::traits::has\_invalid\_input\_versioning&lt; T, InputArchive &gt;**  
struct **cereal::traits::detail::count\_specializations&lt; T, A &gt;**  
Number of specializations detected. struct **cereal::traits::is\_specialized&lt; T, A &gt;**  
Check if any specialization exists for a type. struct **cereal::traits::has\_minimal\_output\_serialization&lt; T, OutputArchive &gt;**  
struct **cereal::traits::has\_minimal\_input\_serialization&lt; T, InputArchive &gt;**  
struct **cereal::traits::detail::count\_output\_serializers&lt; T, OutputArchive &gt;**  
The number of output serialization functions available. struct **cereal::traits::is\_output\_serializable&lt; T, OutputArchive &gt;**  
struct **cereal::traits::detail::count\_input\_serializers&lt; T, InputArchive &gt;**  
The number of input serialization functions available. struct **cereal::traits::is\_input\_serializable&lt; T, InputArchive &gt;**  
struct **cereal::traits::detail::base\_class\_id**  
struct **cereal::traits::detail::base\_class\_id\_hash**  
struct **cereal::traits::detail::BaseCastBase**  
Common base type for base class casting. struct **cereal::traits::detail::get\_base\_class&lt; Cast&lt; Base &gt; &gt;**  
struct **cereal::traits::detail::has\_minimal\_base\_class\_serialization\_impl&lt; Cast, Test, Archive, IsBaseCast &gt;**  
Base class cast, behave as the test. struct **cereal::traits::detail::has\_minimal\_base\_class\_serialization\_impl&lt; Cast, Test, Archive, false &gt;**  
Not a base class cast. struct **cereal::traits::has\_minimal\_base\_class\_serialization&lt; Cast, Test, Archive &gt;**  
Checks to see if the base class used in a cast has a minimal serialization. struct **cereal::traits::detail::shared\_from\_this\_wrapper**  
struct **cereal::traits::has\_shared\_from\_this&lt; T &gt;**  
Determine if T or any base class of T has inherited from std::enable\_shared\_from\_this. struct **cereal::traits::get\_shared\_from\_this\_base&lt; T &gt;**  
Get the type of the base class of T which inherited from std::enable\_shared\_from\_this. struct **cereal::traits::strip\_minimal&lt; T, IsCerealMinimalTrait &gt;**  
Extracts the true type from something possibly wrapped in a cereal NoConvert. struct **cereal::traits::strip\_minimal&lt; T, true &gt;**  
Specialization for types wrapped in a NoConvert. struct **cereal::traits::is\_default\_constructible&lt; T &gt;**  
Determines whether the class T can be default constructed by **cereal::access**. struct **cereal::traits::is\_same\_archive&lt; ArchiveT, CerealArchiveT &gt;**  
Checks if the provided archive type is equal to some cereal archive type. struct **cereal::traits::TextArchive**  
Type traits only struct used to mark an archive as human readable (text based). struct **cereal::traits::is\_text\_archive&lt; A &gt;**  
Checks if an archive is a text archive (human readable). struct **cereal::detail::Construct&lt; T, A, Member, MemberVersioned, NonMember, NonMemberVersioned &gt;**  
struct **cereal::detail::Construct&lt; T, A, false, false, false, false &gt;**  
struct **cereal::detail::Construct&lt; T, A, true, false, false, false &gt;**  
struct **cereal::detail::Construct&lt; T, A, false, true, false, false &gt;**  
struct **cereal::detail::Construct&lt; T, A, false, false, true, false &gt;**  
struct **cereal::detail::Construct&lt; T, A, false, false, false, true &gt;**

## [Macros](#Macros)

#define **CEREAL\_SETUP\_ARCHIVE\_TRAITS**(InputArchive, OutputArchive)  
Sets up traits that relate an input archive to an output archive. #define **CEREAL\_MAKE\_VERSIONED\_TEST** ,0  
Used to convert a MAKE\_HAS\_XXX macro into a versioned variant. #define **CEREAL\_MAKE\_HAS\_MEMBER\_TEST**(name, test\_name, versioned)  
Creates a test for whether a non const member function exists. #define **CEREAL\_MAKE\_HAS\_NON\_MEMBER\_TEST**(test\_name, func, versioned)  
Creates a test for whether a non const non-member function exists. #define **CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_IMPL**(test\_name, versioned)  
Creates a test for whether a member save function exists. #define **CEREAL\_MAKE\_HAS\_NON\_MEMBER\_SAVE\_TEST**(test\_name, versioned)  
Creates a test for whether a non-member save function exists. #define **CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_MINIMAL\_IMPL**(test\_name, versioned)  
Creates implementation details for whether a member save\_minimal function exists. #define **CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_MINIMAL\_HELPERS\_IMPL**(test\_name, versioned)  
Creates helpers for minimal save functions. #define **CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_MINIMAL\_TEST**(test\_name)  
Creates a test for whether a member save\_minimal function exists. #define **CEREAL\_MAKE\_HAS\_NON\_MEMBER\_SAVE\_MINIMAL\_TEST**(test\_name, versioned)  
Creates a test for whether a non-member save\_minimal function exists. #define **CEREAL\_MAKE\_HAS\_MEMBER\_LOAD\_MINIMAL\_IMPL**(test\_name, versioned)  
Creates a test for whether a member load\_minimal function exists. #define **CEREAL\_MAKE\_HAS\_MEMBER\_LOAD\_MINIMAL\_HELPERS\_IMPL**(load\_test\_name, save\_test\_name, save\_test\_prefix, versioned)  
Creates helpers for minimal load functions. #define **CEREAL\_MAKE\_HAS\_MEMBER\_LOAD\_MINIMAL\_TEST**(load\_test\_name, load\_test\_prefix)  
Creates a test for whether a member load\_minimal function exists. #define **CEREAL\_MAKE\_HAS\_NON\_MEMBER\_LOAD\_MINIMAL\_TEST**(test\_name, save\_name, versioned)  
Creates a test for whether a non-member load\_minimal function exists. #define **CEREAL\_MAKE\_HAS\_NON\_MEMBER\_LOAD\_AND\_CONSTRUCT\_TEST**(test\_name, versioned)  
Creates a test for whether a non-member load\_and\_construct specialization exists. #define [**CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL**(name)](/man/enterprise-packages/cereal/CEREAL_MAKE_IS_SPECIALIZED_IMPL.name)  
Create a test for a cereal::specialization entry. #define **CEREAL\_MAKE\_IS\_SPECIALIZED\_ASSERT**(name, versioned\_name, print\_name, spec\_name)  
Create the static assertion for some specialization. #define **CEREAL\_MAKE\_IS\_SPECIALIZED**(name, versioned\_name, spec\_name)  
Generates a test for specialization for versioned and unversioned functions. #define **CEREAL\_ARCHIVE\_RESTRICT**(INTYPE, OUTTYPE)  
A macro to use to restrict which types of archives your function will work for.

## [Typedefs](#Typedefs)

using **cereal::traits::yes** = std::true\_type  
using **cereal::traits::no** = std::false\_type  
template&lt;bool ... Conditions&gt; using **EnableIf** = typename detail::EnableIfHelper&lt;Conditions...&gt;::type  
Provides a way to enable a function if conditions are met. template&lt;bool ... Conditions&gt; using **DisableIf** = typename detail::DisableIfHelper&lt;Conditions...&gt;::type  
Provides a way to disable a function if conditions are met. template&lt;class A&gt; using **cereal::traits::detail::decay\_archive** = typename std::decay&lt;typename **strip\_minimal**&lt;A&gt;::type&gt;::type  
Removes all qualifiers and minimal wrappers from an archive.

## [Enumerations](#Enumerations)

enum class **cereal::traits::detail::sfinae**  
Return type for SFINAE Enablers.

## [Functions](#Functions)

**cereal::traits::CEREAL\_MAKE\_HAS\_MEMBER\_TEST** (**serialize**, **serialize**,)  
**cereal::traits::CEREAL\_MAKE\_HAS\_MEMBER\_TEST** (**serialize**, versioned\_serialize, **CEREAL\_MAKE\_VERSIONED\_TEST**)  
**cereal::traits::CEREAL\_MAKE\_HAS\_NON\_MEMBER\_TEST** (**serialize**, **CEREAL\_SERIALIZE\_FUNCTION\_NAME**,)  
**cereal::traits::CEREAL\_MAKE\_HAS\_NON\_MEMBER\_TEST** (versioned\_serialize, **CEREAL\_SERIALIZE\_FUNCTION\_NAME**, **CEREAL\_MAKE\_VERSIONED\_TEST**)  
**cereal::traits::CEREAL\_MAKE\_HAS\_MEMBER\_TEST** (load, load,)  
**cereal::traits::CEREAL\_MAKE\_HAS\_MEMBER\_TEST** (load, versioned\_load, **CEREAL\_MAKE\_VERSIONED\_TEST**)  
**cereal::traits::CEREAL\_MAKE\_HAS\_NON\_MEMBER\_TEST** (load, **CEREAL\_LOAD\_FUNCTION\_NAME**,)  
**cereal::traits::CEREAL\_MAKE\_HAS\_NON\_MEMBER\_TEST** (versioned\_load, **CEREAL\_LOAD\_FUNCTION\_NAME**, **CEREAL\_MAKE\_VERSIONED\_TEST**)  
**cereal::traits::detail::CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL** (member\_serialize)  
**cereal::traits::detail::CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL** (member\_load\_save)  
**cereal::traits::detail::CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL** (member\_load\_save\_minimal)  
**cereal::traits::detail::CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL** (non\_member\_serialize)  
**cereal::traits::detail::CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL** (non\_member\_load\_save)  
**cereal::traits::detail::CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL** (non\_member\_load\_save\_minimal)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (member\_serialize, member\_versioned\_serialize, member\_serialize)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (non\_member\_serialize, non\_member\_versioned\_serialize, non\_member\_serialize)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (member\_save, member\_versioned\_save, member\_load\_save)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (non\_member\_save, non\_member\_versioned\_save, non\_member\_load\_save)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (member\_load, member\_versioned\_load, member\_load\_save)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (non\_member\_load, non\_member\_versioned\_load, non\_member\_load\_save)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (member\_save\_minimal, member\_versioned\_save\_minimal, member\_load\_save\_minimal)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (non\_member\_save\_minimal, non\_member\_versioned\_save\_minimal, non\_member\_load\_save\_minimal)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (member\_load\_minimal, member\_versioned\_load\_minimal, member\_load\_save\_minimal)  
**cereal::traits::CEREAL\_MAKE\_IS\_SPECIALIZED** (non\_member\_load\_minimal, non\_member\_versioned\_load\_minimal, non\_member\_load\_save\_minimal)

# [Detailed Description](#Detailed_Description)

Internal type trait support.

# [Macro Definition Documentation](#Macro_Definition_Documentation)

## [#define CEREAL\_ARCHIVE\_RESTRICT( INTYPE, OUTTYPE)](#_define_CEREAL_ARCHIVE_RESTRICT%28_INTYPE,__OUTTYPE%29)

**Value:**

```
typename std::enable_if<cereal::traits::is_same_archive<Archive, INTYPE>::value || cereal::traits::is_same_archive<Archive, OUTTYPE>::value, void>::type
```

```

```

A macro to use to restrict which types of archives your function will work for. This requires you to have a template class parameter named Archive and replaces the void return type for your function.

INTYPE refers to the input archive type you wish to restrict on. OUTTYPE refers to the output archive type you wish to restrict on.

For example, if we want to limit a serialize to only work with binary serialization:

```
template <class Archive>
CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive)
serialize( Archive & ar, MyCoolType & m )
{


  ar & m;
}
```

If you need to do more restrictions in your enable\_if, you will need to do this by hand.

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_LOAD\_MINIMAL\_HELPERS\_IMPL( load\_test\_name, save\_test\_name, save\_test\_prefix, versioned)](#_define_CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL%28_load_test_name,__save_test_name,__save_test_prefix,__versioned%29)

**Value:**

```
namespace detail                                                                                                      \
{                                                                                                                     \


  template <class T, class A, bool Valid>                                                                             \


  struct has_member_##load_test_name##_wrapper : std::false_type {};                                                  \


                                                                                                                      \


  template <class T, class A>                                                                                         \


  struct has_member_##load_test_name##_wrapper<T, A, true>                                                            \


  {                                                                                                                   \


    using AOut = typename detail::get_output_from_input<A>::type;                                                     \


                                                                                                                      \


    static_assert( has_member_##save_test_prefix##_minimal<T, AOut>::value,                                           \


      "cereal detected member " #load_test_name " but no valid member " #save_test_name ". \n "                       \


      "cannot evaluate correctness of " #load_test_name " without valid " #save_test_name "." );                      \


                                                                                                                      \


    using SaveType = typename detail::get_member_##save_test_prefix##_minimal_type<T, AOut, true>::type;              \


    const static bool value = has_member_##load_test_name##_impl<T, A>::value;                                        \


    const static bool valid = has_member_##load_test_name##_type_impl<T, A, SaveType>::value;                         \


                                                                                                                      \


    static_assert( valid || !value, "cereal detected different or invalid types in corresponding member "             \


        #load_test_name " and " #save_test_name " functions. \n "                                                     \


        "the paramater to " #load_test_name " must be a constant reference to the type that "                         \


        #save_test_name " returns." );                                                                                \


  };                                                                                                                  \
}
```

```

```

Creates helpers for minimal load functions. The has\_member\_\*\_wrapper structs ensure that the load and save types for the requested function type match appropriately.

**Parameters**

*load\_test\_name* The name to give the test (e.g. load\_minimal or versioned\_load\_minimal)  
*save\_test\_name* The name to give the test (e.g. save\_minimal or versioned\_save\_minimal, should match the load name.  
*save\_test\_prefix* The name to give the test (e.g. save\_minimal or versioned\_save\_minimal, should match the load name, without the trailing "\_minimal" (e.g. save or versioned\_save). Needed because the preprocessor is an abomination.  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_LOAD\_MINIMAL\_IMPL( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL%28_test_name,__versioned%29)

**Value:**

```
namespace detail                                                                    \
{                                                                                   \


  template <class T, class A>                                                       \


  struct has_member_##test_name##_impl                                              \


  {                                                                                 \


    template <class TT, class AA>                                                   \


    static auto test(int) -> decltype( cereal::access::member_load_minimal(         \


          std::declval<AA const &>(),                                               \


          std::declval<TT &>(), AnyConvert() versioned ), yes());                   \


    template <class, class> static no test(...);                                    \


    static const bool value = std::is_same<decltype(test<T, A>(0)), yes>::value;    \


  };                                                                                \


  template <class T, class A, class U>                                              \


  struct has_member_##test_name##_type_impl                                         \


  {                                                                                 \


    template <class TT, class AA, class UU>                                         \


    static auto test(int) -> decltype( cereal::access::member_load_minimal(         \


          std::declval<AA const &>(),                                               \


          std::declval<TT &>(), NoConvertConstRef<UU>() versioned ), yes());        \


    template <class, class, class> static no test(...);                             \


    static const bool value = std::is_same<decltype(test<T, A, U>(0)), yes>::value; \


                                                                                    \


  };                                                                                \
}
```

```

```

Creates a test for whether a member load\_minimal function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

Our strategy here is to first check if a function matching the signature more or less exists (allow anything like load\_minimal(xxx) using AnyConvert, and then secondly enforce that it has the correct signature using NoConvertConstRef

**Parameters**

*test\_name* The name to give the test (e.g. load\_minimal or versioned\_load\_minimal)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_LOAD\_MINIMAL\_TEST( load\_test\_name, load\_test\_prefix)](#_define_CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST%28_load_test_name,__load_test_prefix%29)

**Value:**

```
template <class T, class A>                                                                                                \
struct has_member_##load_test_prefix##_minimal : std::integral_constant<bool,                                              \


  detail::has_member_##load_test_name##_wrapper<T, A, detail::has_member_##load_test_name##_impl<T, A>::value>::value> {};
```

```

```

Creates a test for whether a member load\_minimal function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

**Parameters**

*load\_test\_name* The name to give the test (e.g. load\_minimal or versioned\_load\_minimal)  
*load\_test\_prefix* The above parameter minus the trailing "\_minimal"

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_IMPL( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL%28_test_name,__versioned%29)

**Value:**

```
namespace detail                                                                                                                \
{                                                                                                                               \
template <class T, class A>                                                                                                     \
struct has_member_##test_name##_impl                                                                                            \


  {                                                                                                                             \


    template <class TT, class AA>                                                                                               \


    static auto test(int) -> decltype( cereal::access::member_save( std::declval<AA&>(),                                        \


                                                                    std::declval<TT const &>() versioned ), yes());             \


    template <class, class> static no test(...);                                                                                \


    static const bool value = std::is_same<decltype(test<T, A>(0)), yes>::value;                                                \


                                                                                                                                \


    template <class TT, class AA>                                                                                               \


    static auto test2(int) -> decltype( cereal::access::member_save_non_const(                                                  \


                                          std::declval<AA &>(),                                                                 \


                                          std::declval<typename std::remove_const<TT>::type&>() versioned ), yes());            \


    template <class, class> static no test2(...);                                                                               \


    static const bool not_const_type = std::is_same<decltype(test2<T, A>(0)), yes>::value;                                      \


  };                                                                                                                            \
}
```

```

```

Creates a test for whether a member save function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

**Parameters**

*test\_name* The name to give the test (e.g. save or versioned\_save)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_MINIMAL\_HELPERS\_IMPL( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL%28_test_name,__versioned%29)

**Value:**

```
namespace detail                                                                                         \
{                                                                                                        \


  template <class T, class A, bool Valid>                                                                \


  struct get_member_##test_name##_type { using type = void; };                                           \


                                                                                                         \


  template <class T, class A>                                                                            \


  struct get_member_##test_name##_type<T, A, true>                                                       \


  {                                                                                                      \


    using type = decltype( cereal::access::member_save_minimal( std::declval<A const &>(),               \


                                                                std::declval<T const &>() versioned ) ); \


  };                                                                                                     \
}
```

```

```

Creates helpers for minimal save functions. The get\_member\_\*\_type structs allow access to the return type of a save\_minimal, assuming that the function actually exists. If the function does not exist, the type will be void.

**Parameters**

*test\_name* The name to give the test (e.g. save\_minimal or versioned\_save\_minimal)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_MINIMAL\_IMPL( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL%28_test_name,__versioned%29)

**Value:**

```
namespace detail                                                                           \
{                                                                                          \


  template <class T, class A>                                                              \


  struct has_member_##test_name##_impl                                                     \


  {                                                                                        \


    template <class TT, class AA>                                                          \


    static auto test(int) -> decltype( cereal::access::member_save_minimal(                \


          std::declval<AA const &>(),                                                      \


          std::declval<TT const &>() versioned ), yes());                                  \


    template <class, class> static no test(...);                                           \


    static const bool value = std::is_same<decltype(test<T, A>(0)), yes>::value;           \


                                                                                           \


    template <class TT, class AA>                                                          \


    static auto test2(int) -> decltype( cereal::access::member_save_minimal_non_const(     \


          std::declval<AA const &>(),                                                      \


          std::declval<typename std::remove_const<TT>::type&>() versioned ), yes());       \


    template <class, class> static no test2(...);                                          \


    static const bool not_const_type = std::is_same<decltype(test2<T, A>(0)), yes>::value; \


                                                                                           \


    static const bool valid = value || !not_const_type;                                    \


  };                                                                                       \
}
```

```

```

Creates implementation details for whether a member save\_minimal function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

**Parameters**

*test\_name* The name to give the test (e.g. save\_minimal or versioned\_save\_minimal)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_SAVE\_MINIMAL\_TEST( test\_name)](#_define_CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST%28_test_name%29)

**Value:**

```
template <class T, class A>                                                                                      \
struct has_member_##test_name : std::integral_constant<bool, detail::has_member_##test_name##_impl<T, A>::value> \
{                                                                                                                \


  using check = typename detail::has_member_##test_name##_impl<T, A>;                                            \


  static_assert( check::valid,                                                                                   \


    "cereal detected a non-const member " #test_name ". \n "                                                     \


    #test_name " member functions must always be const" );                                                       \


                                                                                                                 \


  using type = typename detail::get_member_##test_name##_type<T, A, check::value>::type;                         \


  static_assert( (check::value && is_minimal_type<type>::value) || !check::value,                                \


    "cereal detected a member " #test_name " with an invalid return type. \n "                                   \


    "return type must be arithmetic or string" );                                                                \
};
```

```

```

Creates a test for whether a member save\_minimal function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

**Parameters**

*test\_name* The name to give the test (e.g. save\_minimal or versioned\_save\_minimal)

## [#define CEREAL\_MAKE\_HAS\_MEMBER\_TEST( name, test\_name, versioned)](#_define_CEREAL_MAKE_HAS_MEMBER_TEST%28_name,__test_name,__versioned%29)

**Value:**

```
namespace detail                                                                                                                    \
{                                                                                                                                   \


  template <class T, class A>                                                                                                       \


  struct has_member_##name##_##versioned##_impl                                                                                     \


  {                                                                                                                                 \


    template <class TT, class AA>                                                                                                   \


    static auto test(int) -> decltype( cereal::access::member_##name( std::declval<AA&>(), std::declval<TT&>() versioned ), yes()); \


    template <class, class>                                                                                                         \


    static no test(...);                                                                                                            \


    static const bool value = std::is_same<decltype(test<T, A>(0)), yes>::value;                                                    \


  };                                                                                                                                \
}                                                                                                          \
template <class T, class A>                                                                                                         \
struct has_member_##test_name : std::integral_constant<bool, detail::has_member_##name##_##versioned##_impl<T, A>::value> {}
```

```

```

Creates a test for whether a non const member function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

**Parameters**

*name* The name of the function to test for (e.g. serialize, load, save)  
*test\_name* The name to give the test for the function being tested for (e.g. serialize, versioned\_serialize)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_NON\_MEMBER\_LOAD\_AND\_CONSTRUCT\_TEST( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST%28_test_name,__versioned%29)

**Value:**

```
namespace detail                                                                                                            \
{                                                                                                                           \


  template <class T, class A>                                                                                               \


  struct has_non_member_##test_name##_impl                                                                                  \


  {                                                                                                                         \


    template <class TT, class AA>                                                                                           \


    static auto test(int) -> decltype( LoadAndConstruct<TT>::load_and_construct(                                            \


                                       std::declval<AA&>(), std::declval< ::cereal::construct<TT>&>() versioned ), yes());  \


    template <class, class>                                                                                                 \


    static no test( ... );                                                                                                  \


    static const bool value = std::is_same<decltype( test<T, A>( 0 ) ), yes>::value;                                        \


  };                                                                                                                        \
}                                                                                                  \
template <class T, class A>                                                                                                 \
struct has_non_member_##test_name :                                                                                         \


  std::integral_constant<bool, detail::has_non_member_##test_name##_impl<typename std::remove_const<T>::type, A>::value> {};
```

```

```

Creates a test for whether a non-member load\_and\_construct specialization exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper non-member function for the given archive.

## [#define CEREAL\_MAKE\_HAS\_NON\_MEMBER\_LOAD\_MINIMAL\_TEST( test\_name, save\_name, versioned)](#_define_CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST%28_test_name,__save_name,__versioned%29)

Creates a test for whether a non-member load\_minimal function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

See notes from member load\_minimal implementation.

Note that there should be an additional const check on load\_minimal after the valid check, but this currently interferes with many valid uses of minimal serialization. It has been removed (see #565 on github) and previously was:

```
static_assert( check::const_valid || !check::exists,


    "cereal detected an invalid serialization type parameter in non-member " #test_name ".  "


    #test_name " non-member functions must accept their serialization type by non-const reference" );
```

See #132, #436, #263, and #565 on https://github.com/USCiLab/cereal for more details.

**Parameters**

*test\_name* The name to give the test (e.g. load\_minimal or versioned\_load\_minimal)  
*save\_name* The corresponding name the save test would have (e.g. save\_minimal or versioned\_save\_minimal)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_NON\_MEMBER\_SAVE\_MINIMAL\_TEST( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST%28_test_name,__versioned%29)

Creates a test for whether a non-member save\_minimal function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper member function for the given archive.

**Parameters**

*test\_name* The name to give the test (e.g. save\_minimal or versioned\_save\_minimal)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_NON\_MEMBER\_SAVE\_TEST( test\_name, versioned)](#_define_CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST%28_test_name,__versioned%29)

**Value:**

```
namespace detail                                                                                                         \
{                                                                                                                        \


  template <class T, class A>                                                                                            \


  struct has_non_member_##test_name##_impl                                                                               \


  {                                                                                                                      \


    template <class TT, class AA>                                                                                        \


    static auto test(int) -> decltype( CEREAL_SAVE_FUNCTION_NAME(                                                        \


                                          std::declval<AA&>(),                                                           \


                                          std::declval<TT const &>() versioned ), yes());                                \


    template <class, class> static no test(...);                                                                         \


    static const bool value = std::is_same<decltype(test<T, A>(0)), yes>::value;                                         \


                                                                                                                         \


    template <class TT, class AA>                                                                                        \


    static auto test2(int) -> decltype( CEREAL_SAVE_FUNCTION_NAME(                                                       \


                                          std::declval<AA &>(),                                                          \


                                          std::declval<typename std::remove_const<TT>::type&>() versioned ), yes());     \


    template <class, class> static no test2(...);                                                                        \


    static const bool not_const_type = std::is_same<decltype(test2<T, A>(0)), yes>::value;                               \


  };                                                                                                                     \
}                                                                                               \


                                                                                                                         \
template <class T, class A>                                                                                              \
struct has_non_member_##test_name : std::integral_constant<bool, detail::has_non_member_##test_name##_impl<T, A>::value> \
{                                                                                                                        \


  using check = typename detail::has_non_member_##test_name##_impl<T, A>;                                                \


  static_assert( check::value || !check::not_const_type,                                                                 \


    "cereal detected a non-const type parameter in non-member " #test_name ". \n "                                       \


    #test_name " non-member functions must always pass their types as const" );                                          \
};
```

```

```

Creates a test for whether a non-member save function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper non-member function for the given archive.

**Parameters**

*test\_name* The name to give the test (e.g. save or versioned\_save)  
*versioned* Either blank or the macro CEREAL\_MAKE\_VERSIONED\_TEST

## [#define CEREAL\_MAKE\_HAS\_NON\_MEMBER\_TEST( test\_name, func, versioned)](#_define_CEREAL_MAKE_HAS_NON_MEMBER_TEST%28_test_name,__func,__versioned%29)

**Value:**

```
namespace detail                                                                                                            \
{                                                                                                                           \


  template <class T, class A>                                                                                               \


  struct has_non_member_##test_name##_impl                                                                                  \


  {                                                                                                                         \


    template <class TT, class AA>                                                                                           \


    static auto test(int) -> decltype( func( std::declval<AA&>(), std::declval<TT&>() versioned ), yes());                  \


    template <class, class>                                                                                                 \


    static no test( ... );                                                                                                  \


    static const bool value = std::is_same<decltype( test<T, A>( 0 ) ), yes>::value;                                        \


  };                                                                                                                        \
}                                                                                                  \
template <class T, class A>                                                                                                 \
struct has_non_member_##test_name : std::integral_constant<bool, detail::has_non_member_##test_name##_impl<T, A>::value> {}
```

```

```

Creates a test for whether a non const non-member function exists. This creates a class derived from std::integral\_constant that will be true if the type has the proper non-member function for the given archive.

## [#define CEREAL\_MAKE\_IS\_SPECIALIZED( name, versioned\_name, spec\_name)](#_define_CEREAL_MAKE_IS_SPECIALIZED%28_name,__versioned_name,__spec_name%29)

**Value:**

```
template <class T, class A>                                                             \
struct is_specialized_##name : std::integral_constant<bool,                             \


  is_specialized<T, A>::value && detail::is_specialized_##spec_name<T, A>::value>       \
{ CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, name, spec_name); };          \
template <class T, class A>                                                             \
struct is_specialized_##versioned_name : std::integral_constant<bool,                   \


  is_specialized<T, A>::value && detail::is_specialized_##spec_name<T, A>::value>       \
{ CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, versioned_name, spec_name); }
```

```

```

Generates a test for specialization for versioned and unversioned functions. This creates checks that can be queried to see if a given type of serialization function has been specialized for this type

## [#define CEREAL\_MAKE\_IS\_SPECIALIZED\_ASSERT( name, versioned\_name, print\_name, spec\_name)](#_define_CEREAL_MAKE_IS_SPECIALIZED_ASSERT%28_name,__versioned_name,__print_name,__spec_name%29)

**Value:**

```
static_assert( (is_specialized<T, A>::value && detail::is_specialized_##spec_name<T, A>::value &&           \


               (has_##name<T, A>::value || has_##versioned_name<T, A>::value))                              \


               || !(is_specialized<T, A>::value && detail::is_specialized_##spec_name<T, A>::value),        \


               "cereal detected " #print_name " specialization but no " #print_name " serialize function" )
```

```

```

Create the static assertion for some specialization. This assertion will fail if the type is indeed specialized and does not have the appropriate type of serialization functions

## [#define CEREAL\_MAKE\_IS\_SPECIALIZED\_IMPL( name)](#_define_CEREAL_MAKE_IS_SPECIALIZED_IMPL%28_name%29)

**Value:**

```
template <class T, class A>                                                            \
struct is_specialized_##name : std::integral_constant<bool,                            \


  !std::is_base_of<std::false_type, specialize<A, T, specialization::name>>::value> {}
```

```

```

Create a test for a cereal::specialization entry.

## [#define CEREAL\_SETUP\_ARCHIVE\_TRAITS( InputArchive, OutputArchive)](#_define_CEREAL_SETUP_ARCHIVE_TRAITS%28_InputArchive,__OutputArchive%29)

**Value:**

```
namespace cereal { namespace traits { namespace detail {          \


  template <> struct get_output_from_input<InputArchive>          \


  { using type = OutputArchive; };                                \


  template <> struct get_input_from_output<OutputArchive>         \


  { using type = InputArchive; }; } } }
```

```

```

Sets up traits that relate an input archive to an output archive.

# [Typedef Documentation](#Typedef_Documentation)

## template&lt;bool ... Conditions&gt; using **DisableIf** = typename detail::DisableIfHelper&lt;Conditions...&gt;::type

Provides a way to disable a function if conditions are met. This is intended to be used in a near identical fashion to std::enable\_if while being significantly easier to read at the cost of not allowing for as complicated of a condition.

This will compile (allow the function) if every condition evaluates to false. This should be used with SFINAE to ensure that at least one other candidate function works when one fails due to a **DisableIf**.

This should be used as the las template parameter to a function as an unnamed parameter with a default value of cereal::traits::sfinae:

```
// using by making the last template argument variadic
template <class T, DisableIf<std::is_same<T, bool>::value> = sfinae>
void func(T t );
```

This is often used in conjunction with **EnableIf** to form an enable/disable pair of overloads.

Note that this performs a logical AND of all conditions, so you will need to construct more complicated requirements with this fact in mind. If all conditions hold, the function will be disabled.

**Template Parameters**

*Conditions* The conditions which will be logically ANDed to disable the function.

## template&lt;bool ... Conditions&gt; using **EnableIf** = typename detail::EnableIfHelper&lt;Conditions...&gt;::type

Provides a way to enable a function if conditions are met. This is intended to be used in a near identical fashion to std::enable\_if while being significantly easier to read at the cost of not allowing for as complicated of a condition.

This will compile (allow the function) if every condition evaluates to true. at compile time. This should be used with SFINAE to ensure that at least one other candidate function works when one fails due to an **EnableIf**.

This should be used as the las template parameter to a function as an unnamed parameter with a default value of cereal::traits::sfinae:

```
// using by making the last template argument variadic
template <class T, EnableIf<std::is_same<T, bool>::value> = sfinae>
void func(T t );
```

Note that this performs a logical AND of all conditions, so you will need to construct more complicated requirements with this fact in mind.

**Template Parameters**

*Conditions* The conditions which will be logically ANDed to enable the function.

# [Author](#Author)

Generated automatically by Doxygen for cereal from the source code.

Mon Oct 26 2026 02:55:37 cereal

---

Document: traits.hpp(3) from cereal 1.3.2-r7 (Chainguard OS)
Source: https://github.com/USCiLab/cereal
