|
(Note that these are not member functions.)
|
template<class T > |
NameValuePair< T > | make_nvp (std::string const &name, T &&value) |
| Creates a name value pair. More...
|
|
template<class T > |
NameValuePair< T > | make_nvp (const char *name, T &&value) |
| Creates a name value pair. More...
|
|
template<class Archive , class T > |
std::enable_if< std::is_same< Archive,::cereal::BinaryInputArchive >::value||std::is_same< Archive,::cereal::BinaryOutputArchive >::value, T && >::type | make_nvp (const char *, T &&value) |
| A specialization of make_nvp<> that simply forwards the value for binary archives. More...
|
|
template<class Archive , class T > |
std::enable_if<!std::is_same< Archive,::cereal::BinaryInputArchive >::value &&!std::is_same< Archive,::cereal::BinaryOutputArchive >::value, NameValuePair< T > >::type | make_nvp (const char *name, T &&value) |
| A specialization of make_nvp<> that actually creates an nvp for non-binary archives. More...
|
|
template<class T>
class cereal::NameValuePair< T >
For holding name value pairs.
This pairs a name (some string) with some value such that an archive can potentially take advantage of the pairing.
In serialization functions, NameValuePairs are usually created like so:
struct MyStruct
{
template<class Archive>
{
}
};
#define CEREAL_NVP(T)
Creates a name value pair for the variable T with the same name as the variable.
Definition: cereal.hpp:72
void serialize(Archive &, std::less< T > &)
Saving for std::less.
Definition: functional.hpp:39
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
Alternatively, you can give you data members custom names like so:
struct MyStruct
{
int a, b, my_embarrassing_variable_name,
d, e;
template<class Archive>
{
cereal::make_nvp("var", my_embarrassing_variable_name) );
}
};
There is a slight amount of overhead to creating NameValuePairs, so there is a third method which will elide the names when they are not used by the Archive:
struct MyStruct
{
template<class Archive>
{
archive( cereal::make_nvp<Archive>(
a),
cereal::make_nvp<Archive>(b) );
}
};
This third method is generally only used when providing generic type support. Users writing their own serialize functions will normally explicitly control whether they want to use NVPs or not.