cereal
A C++11 library for serialization
Classes | Macros | Typedefs | Enumerations | Functions
traits.hpp File Reference

Internal type trait support. More...

#include <type_traits>
#include <typeindex>
#include "cereal/macros.hpp"
#include "cereal/access.hpp"

Go to the source code of this file.

Classes

struct  cereal::traits::detail::delay_static_assert< T >
 Used to delay a static_assert until template instantiation. More...
 
struct  cereal::traits::detail::meta_bool_and< H, T >
 
struct  cereal::traits::detail::meta_bool_and< B >
 
struct  cereal::traits::detail::meta_bool_or< H, T >
 
struct  cereal::traits::detail::meta_bool_or< B >
 
struct  cereal::traits::detail::EnableIfHelper< Conditions >
 
struct  cereal::traits::detail::DisableIfHelper< Conditions >
 
struct  cereal::traits::detail::get_output_from_input< InputArchive >
 
struct  cereal::traits::detail::get_input_from_output< OutputArchive >
 
struct  cereal::traits::has_member_save< T, A >
 
struct  cereal::traits::has_member_versioned_save< T, A >
 
struct  cereal::traits::detail::is_string< class >
 
struct  cereal::traits::detail::is_string< std::basic_string< CharT, Traits, Alloc > >
 
struct  cereal::traits::is_minimal_type< T >
 
struct  cereal::traits::detail::NoConvertBase
 Used to help strip away conversion wrappers. More...
 
struct  cereal::traits::detail::NoConvertConstRef< Source >
 A struct that prevents implicit conversion. More...
 
struct  cereal::traits::detail::NoConvertRef< Source >
 A struct that prevents implicit conversion. More...
 
struct  cereal::traits::detail::AnyConvert
 A type that can implicitly convert to anything else. More...
 
struct  cereal::traits::detail::has_member_load_and_construct_impl< T, A >
 
struct  cereal::traits::detail::has_member_versioned_load_and_construct_impl< T, A >
 
struct  cereal::traits::has_member_load_and_construct< T, A >
 Member load and construct check. More...
 
struct  cereal::traits::has_member_versioned_load_and_construct< T, A >
 Member load and construct check (versioned) More...
 
struct  cereal::traits::has_load_and_construct< T, A >
 Non member load and construct check. More...
 
struct  cereal::traits::has_member_split< T, InputArchive, OutputArchive >
 
struct  cereal::traits::has_non_member_split< T, InputArchive, OutputArchive >
 
struct  cereal::traits::has_invalid_output_versioning< T, OutputArchive >
 
struct  cereal::traits::has_invalid_input_versioning< T, InputArchive >
 
struct  cereal::traits::detail::count_specializations< T, A >
 Number of specializations detected. More...
 
struct  cereal::traits::is_specialized< T, A >
 Check if any specialization exists for a type. More...
 
struct  cereal::traits::has_minimal_output_serialization< T, OutputArchive >
 
struct  cereal::traits::has_minimal_input_serialization< T, InputArchive >
 
struct  cereal::traits::detail::count_output_serializers< T, OutputArchive >
 The number of output serialization functions available. More...
 
struct  cereal::traits::is_output_serializable< T, OutputArchive >
 
struct  cereal::traits::detail::count_input_serializers< T, InputArchive >
 The number of input serialization functions available. More...
 
struct  cereal::traits::is_input_serializable< T, InputArchive >
 
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. More...
 
struct  cereal::traits::detail::get_base_class< Cast< Base > >
 
struct  cereal::traits::detail::has_minimal_base_class_serialization_impl< Cast, Test, Archive, IsBaseCast >
 Base class cast, behave as the test. More...
 
struct  cereal::traits::detail::has_minimal_base_class_serialization_impl< Cast, Test, Archive, false >
 Not a base class cast. More...
 
struct  cereal::traits::has_minimal_base_class_serialization< Cast, Test, Archive >
 Checks to see if the base class used in a cast has a minimal serialization. More...
 
struct  cereal::traits::detail::shared_from_this_wrapper
 
struct  cereal::traits::has_shared_from_this< T >
 Determine if T or any base class of T has inherited from std::enable_shared_from_this. More...
 
struct  cereal::traits::get_shared_from_this_base< T >
 Get the type of the base class of T which inherited from std::enable_shared_from_this. More...
 
struct  cereal::traits::strip_minimal< T, IsCerealMinimalTrait >
 Extracts the true type from something possibly wrapped in a cereal NoConvert. More...
 
struct  cereal::traits::strip_minimal< T, true >
 Specialization for types wrapped in a NoConvert. More...
 
struct  cereal::traits::is_default_constructible< T >
 Determines whether the class T can be default constructed by cereal::access. More...
 
struct  cereal::traits::is_same_archive< ArchiveT, CerealArchiveT >
 Checks if the provided archive type is equal to some cereal archive type. More...
 
struct  cereal::traits::TextArchive
 Type traits only struct used to mark an archive as human readable (text based) More...
 
struct  cereal::traits::is_text_archive< A >
 Checks if an archive is a text archive (human readable) More...
 
struct  cereal::detail::Construct< T, A, Member, MemberVersioned, NonMember, NonMemberVersioned >
 
struct  cereal::detail::Construct< T, A, false, false, false, false >
 
struct  cereal::detail::Construct< T, A, true, false, false, false >
 
struct  cereal::detail::Construct< T, A, false, true, false, false >
 
struct  cereal::detail::Construct< T, A, false, false, true, false >
 
struct  cereal::detail::Construct< T, A, false, false, false, true >
 

Macros

#define CEREAL_SETUP_ARCHIVE_TRAITS(InputArchive, OutputArchive)
 Sets up traits that relate an input archive to an output archive. More...
 
#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. More...
 
#define CEREAL_MAKE_HAS_NON_MEMBER_TEST(test_name, func, versioned)
 Creates a test for whether a non const non-member function exists. More...
 
#define CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL(test_name, versioned)
 Creates a test for whether a member save function exists. More...
 
#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST(test_name, versioned)
 Creates a test for whether a non-member save function exists. More...
 
#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL(test_name, versioned)
 Creates implementation details for whether a member save_minimal function exists. More...
 
#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL(test_name, versioned)
 Creates helpers for minimal save functions. More...
 
#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST(test_name)
 Creates a test for whether a member save_minimal function exists. More...
 
#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST(test_name, versioned)
 Creates a test for whether a non-member save_minimal function exists. More...
 
#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL(test_name, versioned)
 Creates a test for whether a member load_minimal function exists. More...
 
#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. More...
 
#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. More...
 
#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. More...
 
#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. More...
 
#define CEREAL_MAKE_IS_SPECIALIZED_IMPL(name)
 Create a test for a cereal::specialization entry. More...
 
#define CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, print_name, spec_name)
 Create the static assertion for some specialization. More...
 
#define CEREAL_MAKE_IS_SPECIALIZED(name, versioned_name, spec_name)
 Generates a test for specialization for versioned and unversioned functions. More...
 
#define CEREAL_ARCHIVE_RESTRICT(INTYPE, OUTTYPE)    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. More...
 

Typedefs

using cereal::traits::yes = std::true_type
 
using cereal::traits::no = std::false_type
 
template<bool ... Conditions>
using EnableIf = typename detail::EnableIfHelper< Conditions... >::type
 Provides a way to enable a function if conditions are met. More...
 
template<bool ... Conditions>
using DisableIf = typename detail::DisableIfHelper< Conditions... >::type
 Provides a way to disable a function if conditions are met. More...
 
template<class A >
using cereal::traits::detail::decay_archive = typename std::decay< typename strip_minimal< A >::type >::type
 Removes all qualifiers and minimal wrappers from an archive.
 

Enumerations

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

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

Internal type trait support.

Macro Definition Documentation

◆ CEREAL_ARCHIVE_RESTRICT

#define CEREAL_ARCHIVE_RESTRICT (   INTYPE,
  OUTTYPE 
)     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;
}
#define CEREAL_ARCHIVE_RESTRICT(INTYPE, OUTTYPE)
A macro to use to restrict which types of archives your function will work for.
Definition: traits.hpp:1315

If you need to do more restrictions in your enable_if, you will need to do this by hand.

◆ CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL

#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL (   load_test_name,
  save_test_name,
  save_test_prefix,
  versioned 
)
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." ); \
}; \
} /* end namespace detail */

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_nameThe name to give the test (e.g. load_minimal or versioned_load_minimal)
save_test_nameThe name to give the test (e.g. save_minimal or versioned_save_minimal, should match the load name.
save_test_prefixThe 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.
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL

#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL (   test_name,
  versioned 
)
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; \
\
}; \
} /* end namespace detail */

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_nameThe name to give the test (e.g. load_minimal or versioned_load_minimal)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST

#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST (   load_test_name,
  load_test_prefix 
)
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_nameThe name to give the test (e.g. load_minimal or versioned_load_minimal)
load_test_prefixThe above parameter minus the trailing "_minimal"

◆ CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL

#define CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL (   test_name,
  versioned 
)
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; \
}; \
} /* end namespace detail */

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_nameThe name to give the test (e.g. save or versioned_save)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL

#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL (   test_name,
  versioned 
)
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 ) ); \
}; \
} /* end namespace detail */

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_nameThe name to give the test (e.g. save_minimal or versioned_save_minimal)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL

#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL (   test_name,
  versioned 
)
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; \
}; \
} /* end namespace detail */

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_nameThe name to give the test (e.g. save_minimal or versioned_save_minimal)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST

#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST (   test_name)
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_nameThe name to give the test (e.g. save_minimal or versioned_save_minimal)

◆ CEREAL_MAKE_HAS_MEMBER_TEST

#define CEREAL_MAKE_HAS_MEMBER_TEST (   name,
  test_name,
  versioned 
)
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; \
}; \
} /* end namespace detail */ \
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
nameThe name of the function to test for (e.g. serialize, load, save)
test_nameThe name to give the test for the function being tested for (e.g. serialize, versioned_serialize)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST

#define CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST (   test_name,
  versioned 
)
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; \
}; \
} /* end namespace detail */ \
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> {};
Used to construct types with no default constructor.
Definition: access.hpp:165

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.

◆ CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST

#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.

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_nameThe name to give the test (e.g. load_minimal or versioned_load_minimal)
save_nameThe corresponding name the save test would have (e.g. save_minimal or versioned_save_minimal)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST

#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST (   test_name,
  versioned 
)

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_nameThe name to give the test (e.g. save_minimal or versioned_save_minimal)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST

#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST (   test_name,
  versioned 
)
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; \
}; \
} /* end namespace detail */ \
\
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" ); \
};
#define CEREAL_SAVE_FUNCTION_NAME
The serialization (save) function name to search for.
Definition: macros.hpp:92

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_nameThe name to give the test (e.g. save or versioned_save)
versionedEither blank or the macro CEREAL_MAKE_VERSIONED_TEST

◆ CEREAL_MAKE_HAS_NON_MEMBER_TEST

#define CEREAL_MAKE_HAS_NON_MEMBER_TEST (   test_name,
  func,
  versioned 
)
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; \
}; \
} /* end namespace detail */ \
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.

◆ CEREAL_MAKE_IS_SPECIALIZED

#define CEREAL_MAKE_IS_SPECIALIZED (   name,
  versioned_name,
  spec_name 
)
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); }
#define CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, print_name, spec_name)
Create the static assertion for some specialization.
Definition: traits.hpp:1028

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

◆ CEREAL_MAKE_IS_SPECIALIZED_ASSERT

#define CEREAL_MAKE_IS_SPECIALIZED_ASSERT (   name,
  versioned_name,
  print_name,
  spec_name 
)
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

◆ CEREAL_MAKE_IS_SPECIALIZED_IMPL

#define CEREAL_MAKE_IS_SPECIALIZED_IMPL (   name)
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.

◆ CEREAL_SETUP_ARCHIVE_TRAITS

#define CEREAL_SETUP_ARCHIVE_TRAITS (   InputArchive,
  OutputArchive 
)
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; }; } } } /* end namespaces */

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

Typedef Documentation

◆ DisableIf

template<bool ... Conditions>
using DisableIf = typename detail::DisableIfHelper<Conditions...>::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
ConditionsThe conditions which will be logically ANDed to disable the function.

◆ EnableIf

template<bool ... Conditions>
using EnableIf = typename detail::EnableIfHelper<Conditions...>::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
ConditionsThe conditions which will be logically ANDed to enable the function.