| Home | Libraries | People | FAQ | More

## nvp

### Overview

The header <boost/core/nvp.hpp> provides the class template `boost::nvp` that pairs a name (`const char*`) with the address of a value (`T*`). It is the new implementation of the NVP type previously provided by the Boost Serialization library. This type now lives in the Core library so that other Boost libraries can support named value serialization without taking a dependency on the Serialization library.

### Examples

The following snippet shows use in a member serialize function:

    template<class A>
    void serialize(A& archive, unsigned)
    {
        archive & boost::make_nvp("x", x_) & boost::make_nvp("y", y_);
    }

### Reference

    namespace boost {

    template<class T>
    class nvp {
    public:
        nvp(const char* name, T& value) noexcept;

        const char* name() const noexcept;

        T& value() const noexcept;

        const T& const_value() const noexcept;
    };

    template<class T>
    const nvp<T> make_nvp(const char* name, T& value) noexcept;

    } /* boost */

    #define BOOST_NVP(object) see below

#### Constructors

`nvp(const char* name, T& value) noexcept;`

  Initializes the stored name pointer with `name` and the value pointer with `addressof(value)`.

#### Members

`const char* name() const noexcept;`

  Returns a pointer to the name.

`T& value() const noexcept;`

  Returns a reference to the value.

`const T& const_value() const noexcept;`

  Returns a reference to the value.

#### Functions

`template<class T> const nvp<T> make_nvp(const char* name, T& value) noexcept;`

  Returns `nvp<T>(name, value)`.

#### Macros

`#define BOOST_NVP(object) see below`

  Expands to `boost::make_nvp(BOOST_STRINGIZE(object), object)`.

### History

Robert Ramey originally implemented NVP in the Serialization library. Glen Fernandes implemented this new (but compatible) version in the Core library.