1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>nvp</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../index.html" title="Chapter 1. Boost.Core"> 8<link rel="up" href="../index.html" title="Chapter 1. Boost.Core"> 9<link rel="prev" href="null_deleter.html" title="null_deleter"> 10<link rel="next" href="pointer_traits.html" title="pointer_traits"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="null_deleter.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="pointer_traits.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 27<a name="core.nvp"></a><a class="link" href="nvp.html" title="nvp">nvp</a> 28</h2></div></div></div> 29<div class="toc"><dl class="toc"> 30<dt><span class="section"><a href="nvp.html#core.nvp.overview">Overview</a></span></dt> 31<dt><span class="section"><a href="nvp.html#core.nvp.examples">Examples</a></span></dt> 32<dt><span class="section"><a href="nvp.html#core.nvp.reference">Reference</a></span></dt> 33<dt><span class="section"><a href="nvp.html#core.nvp.history">History</a></span></dt> 34</dl></div> 35<div class="section"> 36<div class="titlepage"><div><div><h3 class="title"> 37<a name="core.nvp.overview"></a><a class="link" href="nvp.html#core.nvp.overview" title="Overview">Overview</a> 38</h3></div></div></div> 39<p> 40 The header <boost/core/nvp.hpp> provides the class template <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">nvp</span></code> that pairs a name (<code class="computeroutput"><span class="keyword">const</span> 41 <span class="keyword">char</span><span class="special">*</span></code>) 42 with the address of a value (<code class="computeroutput"><span class="identifier">T</span><span class="special">*</span></code>). It is the new implementation of the NVP 43 type previously provided by the Boost Serialization library. This type now 44 lives in the Core library so that other Boost libraries can support named 45 value serialization without taking a dependency on the Serialization library. 46 </p> 47</div> 48<div class="section"> 49<div class="titlepage"><div><div><h3 class="title"> 50<a name="core.nvp.examples"></a><a class="link" href="nvp.html#core.nvp.examples" title="Examples">Examples</a> 51</h3></div></div></div> 52<p> 53 The following snippet shows use in a member serialize function: 54 </p> 55<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">></span> 56<span class="keyword">void</span> <span class="identifier">serialize</span><span class="special">(</span><span class="identifier">A</span><span class="special">&</span> <span class="identifier">archive</span><span class="special">,</span> <span class="keyword">unsigned</span><span class="special">)</span> 57<span class="special">{</span> 58 <span class="identifier">archive</span> <span class="special">&</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_nvp</span><span class="special">(</span><span class="string">"x"</span><span class="special">,</span> <span class="identifier">x_</span><span class="special">)</span> <span class="special">&</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_nvp</span><span class="special">(</span><span class="string">"y"</span><span class="special">,</span> <span class="identifier">y_</span><span class="special">);</span> 59<span class="special">}</span> 60</pre> 61</div> 62<div class="section"> 63<div class="titlepage"><div><div><h3 class="title"> 64<a name="core.nvp.reference"></a><a class="link" href="nvp.html#core.nvp.reference" title="Reference">Reference</a> 65</h3></div></div></div> 66<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 67 68<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 69<span class="keyword">class</span> <span class="identifier">nvp</span> <span class="special">{</span> 70<span class="keyword">public</span><span class="special">:</span> 71 <span class="identifier">nvp</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">value</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 72 73 <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 74 75 <span class="identifier">T</span><span class="special">&</span> <span class="identifier">value</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 76 77 <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">const_value</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 78<span class="special">};</span> 79 80<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 81<span class="keyword">const</span> <span class="identifier">nvp</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">make_nvp</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">value</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 82 83<span class="special">}</span> <span class="comment">/* boost */</span> 84 85<span class="preprocessor">#define</span> <span class="identifier">BOOST_NVP</span><span class="special">(</span><span class="identifier">object</span><span class="special">)</span> <span class="emphasis"><em>see below</em></span> 86</pre> 87<div class="section"> 88<div class="titlepage"><div><div><h4 class="title"> 89<a name="core.nvp.reference.constructors"></a><a class="link" href="nvp.html#core.nvp.reference.constructors" title="Constructors">Constructors</a> 90</h4></div></div></div> 91<div class="variablelist"> 92<p class="title"><b></b></p> 93<dl class="variablelist"> 94<dt><span class="term"><code class="computeroutput"><span class="identifier">nvp</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">value</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt> 95<dd><p> 96 Initializes the stored name pointer with <code class="computeroutput"><span class="identifier">name</span></code> 97 and the value pointer with <code class="computeroutput"><span class="identifier">addressof</span><span class="special">(</span><span class="identifier">value</span><span class="special">)</span></code>. 98 </p></dd> 99</dl> 100</div> 101</div> 102<div class="section"> 103<div class="titlepage"><div><div><h4 class="title"> 104<a name="core.nvp.reference.members"></a><a class="link" href="nvp.html#core.nvp.reference.members" title="Members">Members</a> 105</h4></div></div></div> 106<div class="variablelist"> 107<p class="title"><b></b></p> 108<dl class="variablelist"> 109<dt><span class="term"><code class="computeroutput"><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt> 110<dd><p> 111 Returns a pointer to the name. 112 </p></dd> 113<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span><span class="special">&</span> 114 <span class="identifier">value</span><span class="special">()</span> 115 <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt> 116<dd><p> 117 Returns a reference to the value. 118 </p></dd> 119<dt><span class="term"><code class="computeroutput"><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">const_value</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt> 120<dd><p> 121 Returns a reference to the value. 122 </p></dd> 123</dl> 124</div> 125</div> 126<div class="section"> 127<div class="titlepage"><div><div><h4 class="title"> 128<a name="core.nvp.reference.functions"></a><a class="link" href="nvp.html#core.nvp.reference.functions" title="Functions">Functions</a> 129</h4></div></div></div> 130<div class="variablelist"> 131<p class="title"><b></b></p> 132<dl class="variablelist"> 133<dt><span class="term"><code class="computeroutput"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">const</span> <span class="identifier">nvp</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">make_nvp</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">value</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt> 134<dd><p> 135 Returns <code class="computeroutput"><span class="identifier">nvp</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">name</span><span class="special">,</span> 136 <span class="identifier">value</span><span class="special">)</span></code>. 137 </p></dd> 138</dl> 139</div> 140</div> 141<div class="section"> 142<div class="titlepage"><div><div><h4 class="title"> 143<a name="core.nvp.reference.macros"></a><a class="link" href="nvp.html#core.nvp.reference.macros" title="Macros">Macros</a> 144</h4></div></div></div> 145<div class="variablelist"> 146<p class="title"><b></b></p> 147<dl class="variablelist"> 148<dt><span class="term"><code class="computeroutput"><span class="preprocessor">#define</span> <span class="identifier">BOOST_NVP</span><span class="special">(</span><span class="identifier">object</span><span class="special">)</span> <span class="identifier">see</span> <span class="identifier">below</span></code></span></dt> 149<dd><p> 150 Expands to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_nvp</span><span class="special">(</span><span class="identifier">BOOST_STRINGIZE</span><span class="special">(</span><span class="identifier">object</span><span class="special">),</span> <span class="identifier">object</span><span class="special">)</span></code>. 151 </p></dd> 152</dl> 153</div> 154</div> 155</div> 156<div class="section"> 157<div class="titlepage"><div><div><h3 class="title"> 158<a name="core.nvp.history"></a><a class="link" href="nvp.html#core.nvp.history" title="History">History</a> 159</h3></div></div></div> 160<p> 161 Robert Ramey originally implemented NVP in the Serialization library. Glen 162 Fernandes implemented this new (but compatible) version in the Core library. 163 </p> 164</div> 165</div> 166<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 167<td align="left"></td> 168<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p> 169 Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost 170 Software License, Version 1.0</a>. 171 </p> 172</div></td> 173</tr></table> 174<hr> 175<div class="spirit-nav"> 176<a accesskey="p" href="null_deleter.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="pointer_traits.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> 177</div> 178</body> 179</html> 180