.TH "cereal::NameValuePair< T >" 3 "Sat Aug 29 2026 00:42:30" "cereal" \" -*- nroff -*- .ad l .nh .SH NAME cereal::NameValuePair< T > \- For holding name value pairs\&. .SH SYNOPSIS .br .PP .PP \fR#include \fP .PP Inherits \fBcereal::detail::NameValuePairCore\fP\&. .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBNameValuePair\fP (char const *n, T &&v)" .br .RI "Constructs a new \fBNameValuePair\fP\&. " .in -1c .SS "Public Attributes" .in +1c .ti -1c .RI "char const * \fBname\fP" .br .ti -1c .RI "Type \fBvalue\fP" .br .in -1c .SS "Related Symbols" (Note that these are not member symbols\&.) .in +1c .ti -1c .RI "template \fBNameValuePair\fP< T > \fBmake_nvp\fP (std::string const &name, T &&value)" .br .RI "Creates a name value pair\&. " .ti -1c .RI "template \fBNameValuePair\fP< T > \fBmake_nvp\fP (const char *name, T &&value)" .br .RI "Creates a name value pair\&. " .ti -1c .RI "template std::enable_if< std::is_same< Archive,\fB::cereal::BinaryInputArchive\fP >::value||std::is_same< Archive,\fB::cereal::BinaryOutputArchive\fP >::value, T && >::type \fBmake_nvp\fP (const char *, T &&value)" .br .RI "A specialization of make_nvp<> that simply forwards the value for binary archives\&. " .ti -1c .RI "template std::enable_if::value &&!std::is_same< Archive,\fB::cereal::BinaryOutputArchive\fP >::value, \fBNameValuePair\fP< T > >::type \fBmake_nvp\fP (const char *name, T &&value)" .br .RI "A specialization of make_nvp<> that actually creates an nvp for non-binary archives\&. " .in -1c .SH "Detailed Description" .PP .SS "template .br 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\&. .PP In serialization functions, NameValuePairs are usually created like so: .PP .nf struct MyStruct { int a, b, c, d, e; template void serialize(Archive & archive) { archive( CEREAL_NVP(a), CEREAL_NVP(b), CEREAL_NVP(c), CEREAL_NVP(d), CEREAL_NVP(e) ); } }; .fi .PP .PP Alternatively, you can give you data members custom names like so: .PP .nf struct MyStruct { int a, b, my_embarrassing_variable_name, d, e; template void serialize(Archive & archive) { archive( CEREAL_NVP(a), CEREAL_NVP(b), cereal::make_nvp("var", my_embarrassing_variable_name) ); CEREAL_NVP(d), CEREAL_NVP(e) ); } }; .fi .PP .PP 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: .PP .PP .nf struct MyStruct { int a, b; template void serialize(Archive & archive) { archive( cereal::make_nvp(a), cereal::make_nvp(b) ); } }; .fi .PP .PP 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\&. .SH "Constructor & Destructor Documentation" .PP .SS "template \fBcereal::NameValuePair\fP< T >::NameValuePair (char const * n, T && v)\fR [inline]\fP" .PP Constructs a new \fBNameValuePair\fP\&. .PP \fBParameters\fP .RS 4 \fIn\fP The name of the pair .br \fIv\fP The value to pair\&. Ideally this should be an l-value reference so that the value can be both loaded and saved to\&. If you pass an r-value reference, the \fBNameValuePair\fP will store a copy of it instead of a reference\&. Thus you should only pass r-values in cases where this makes sense, such as the result of some size() call\&. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for cereal from the source code\&.