cereal::NameValuePair&lt; T &gt;(3) Library Functions Manual cereal::NameValuePair&lt; T &gt;(3)

# [NAME](#NAME)

cereal::NameValuePair&lt; T &gt; - For holding name value pairs.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;/home/build/include/cereal/details/helpers.hpp&gt;

Inherits **cereal::detail::NameValuePairCore**.

## [Public Member Functions](#Public_Member_Functions)

**NameValuePair** (char const \*n, T &&v)  
Constructs a new **NameValuePair**.

## [Public Attributes](#Public_Attributes)

char const * **name**  
Type **value**

## [Related Symbols](#Related_Symbols)

(Note that these are not member symbols.)  
template&lt;class T&gt; **NameValuePair**&lt; T &gt; **make\_nvp** (std::string const &name, T &&value)  
Creates a name value pair. template&lt;class T&gt; **NameValuePair**&lt; T &gt; **make\_nvp** (const char \*name, T &&value)  
Creates a name value pair. template&lt;class Archive, class T&gt; std::enable\_if&lt; std::is\_same&lt; Archive,**::cereal::BinaryInputArchive** &gt;::value||std::is\_same&lt; Archive,**::cereal::BinaryOutputArchive** &gt;::value, T && &gt;::type **make\_nvp** (const char \*, T &&value)  
A specialization of make\_nvp&lt;&gt; that simply forwards the value for binary archives. template&lt;class Archive, class T&gt; std::enable\_if&lt;!std::is\_same&lt; Archive,**::cereal::BinaryInputArchive** &gt;::value &&!std::is\_same&lt; Archive,**::cereal::BinaryOutputArchive** &gt;::value, **NameValuePair**&lt; T &gt; &gt;::type **make\_nvp** (const char \*name, T &&value)  
A specialization of make\_nvp&lt;&gt; that actually creates an nvp for non-binary archives.

# [Detailed Description](#Detailed_Description)

## [template&lt;class T&gt;](#template_class_T_)

class cereal::NameValuePair&lt; T &gt;"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
{


  int a, b, c, d, e;


  template<class Archive>


  void serialize(Archive & archive)


  {


    archive( CEREAL_NVP(a),


             CEREAL_NVP(b),


             CEREAL_NVP(c),


             CEREAL_NVP(d),


             CEREAL_NVP(e) );


  }
};
```

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>


  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) );


  }
};
```

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
{


  int a, b;


  template<class Archive>


  void serialize(Archive & 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.

# [Constructor & Destructor Documentation](#Constructor_&_Destructor_Documentation)

## [template&lt;class T&gt; **cereal::NameValuePair**&lt; T &gt;::NameValuePair (char const * n, T && v) \[inline\]](#template_class_T__)

Constructs a new **NameValuePair**.

**Parameters**

*n* The name of the pair  
*v* 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 **NameValuePair** 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.

# [Author](#Author)

Generated automatically by Doxygen for cereal from the source code.

Sat Oct 10 2026 08:08:15 cereal

---

Document: cereal_NameValuePair(3) from cereal 1.3.2-r6 (Chainguard OS)
Source: https://github.com/USCiLab/cereal
