3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Compressed_Pair</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="compressed_pair.html" title="Compressed_Pair">
9 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
10 <table cellpadding="2" width="100%"><tr>
11 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
12 <td align="center"><a href="../../../../index.html">Home</a></td>
13 <td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
14 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
15 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
16 <td align="center"><a href="../../../../more/index.htm">More</a></td>
19 <div class="spirit-nav"></div>
21 <div class="titlepage">
23 <div><h2 class="title">
24 <a name="compressed_pair"></a>Compressed_Pair</h2></div>
25 <div><div class="authorgroup">
26 <div class="author"><h3 class="author">
27 <span class="firstname">Steve</span> <span class="surname">Cleary</span>
29 <div class="author"><h3 class="author">
30 <span class="firstname">Beman</span> <span class="surname">Dawes</span>
32 <div class="author"><h3 class="author">
33 <span class="firstname">Howard</span> <span class="surname">Hinnant</span>
35 <div class="author"><h3 class="author">
36 <span class="firstname">John</span> <span class="surname">Maddock</span>
39 <div><p class="copyright">Copyright © 2000 Steve Cleary, Beman Dawes, Howard Hinnant & John
41 <div><div class="legalnotice">
42 <a name="compressed_pair.legal"></a><p>
43 Distributed under the Boost Software License, Version 1.0. (See accompanying
44 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
51 <p><b>Table of Contents</b></p>
53 <dt><span class="section"><a href="compressed_pair.html#compressed_pair.overview">Overview</a></span></dt>
54 <dt><span class="section"><a href="compressed_pair.html#compressed_pair.synopsis">Synopsis</a></span></dt>
55 <dt><span class="section"><a href="compressed_pair.html#compressed_pair.acknowledgments">Acknowledgments</a></span></dt>
59 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
60 <a name="compressed_pair.overview"></a><a class="link" href="compressed_pair.html#compressed_pair.overview" title="Overview">Overview</a>
61 </h2></div></div></div>
63 All of the contents of <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">compressed_pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
64 are defined inside <code class="computeroutput"><span class="keyword">namespace</span> <span class="identifier">boost</span></code>.
67 The class <code class="computeroutput"><span class="identifier">compressed_pair</span></code> is
68 very similar to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code>, but if either of the template arguments
69 are empty classes, then the <span class="emphasis"><em>empty base-class optimisation</em></span>
70 is applied to compress the size of the pair.
74 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
75 <a name="compressed_pair.synopsis"></a><a class="link" href="compressed_pair.html#compressed_pair.synopsis" title="Synopsis">Synopsis</a>
76 </h2></div></div></div>
77 <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span>
78 <span class="keyword">class</span> <span class="identifier">compressed_pair</span>
79 <span class="special">{</span>
80 <span class="keyword">public</span><span class="special">:</span>
81 <span class="keyword">typedef</span> <span class="identifier">T1</span> <span class="identifier">first_type</span><span class="special">;</span>
82 <span class="keyword">typedef</span> <span class="identifier">T2</span> <span class="identifier">second_type</span><span class="special">;</span>
83 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">call_traits</span><span class="special"><</span><span class="identifier">first_type</span><span class="special">>::</span><span class="identifier">param_type</span> <span class="identifier">first_param_type</span><span class="special">;</span>
84 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">call_traits</span><span class="special"><</span><span class="identifier">second_type</span><span class="special">>::</span><span class="identifier">param_type</span> <span class="identifier">second_param_type</span><span class="special">;</span>
85 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">call_traits</span><span class="special"><</span><span class="identifier">first_type</span><span class="special">>::</span><span class="identifier">reference</span> <span class="identifier">first_reference</span><span class="special">;</span>
86 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">call_traits</span><span class="special"><</span><span class="identifier">second_type</span><span class="special">>::</span><span class="identifier">reference</span> <span class="identifier">second_reference</span><span class="special">;</span>
87 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">call_traits</span><span class="special"><</span><span class="identifier">first_type</span><span class="special">>::</span><span class="identifier">const_reference</span> <span class="identifier">first_const_reference</span><span class="special">;</span>
88 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">call_traits</span><span class="special"><</span><span class="identifier">second_type</span><span class="special">>::</span><span class="identifier">const_reference</span> <span class="identifier">second_const_reference</span><span class="special">;</span>
90 <span class="identifier">compressed_pair</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">base</span><span class="special">()</span> <span class="special">{}</span>
91 <span class="identifier">compressed_pair</span><span class="special">(</span><span class="identifier">first_param_type</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">second_param_type</span> <span class="identifier">y</span><span class="special">);</span>
92 <span class="keyword">explicit</span> <span class="identifier">compressed_pair</span><span class="special">(</span><span class="identifier">first_param_type</span> <span class="identifier">x</span><span class="special">);</span>
93 <span class="keyword">explicit</span> <span class="identifier">compressed_pair</span><span class="special">(</span><span class="identifier">second_param_type</span> <span class="identifier">y</span><span class="special">);</span>
95 <span class="identifier">compressed_pair</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">compressed_pair</span><span class="special">&);</span>
97 <span class="identifier">first_reference</span> <span class="identifier">first</span><span class="special">();</span>
98 <span class="identifier">first_const_reference</span> <span class="identifier">first</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
100 <span class="identifier">second_reference</span> <span class="identifier">second</span><span class="special">();</span>
101 <span class="identifier">second_const_reference</span> <span class="identifier">second</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
103 <span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">compressed_pair</span><span class="special">&</span> <span class="identifier">y</span><span class="special">);</span>
104 <span class="special">};</span>
107 The two members of the pair can be accessed using the member functions <code class="computeroutput"><span class="identifier">first</span><span class="special">()</span></code> and
108 <code class="computeroutput"><span class="identifier">second</span><span class="special">()</span></code>.
109 Note that not all member functions can be instantiated for all template parameter
110 types. In particular <code class="computeroutput"><span class="identifier">compressed_pair</span></code>
111 can be instantiated for reference and array types, however in these cases the
112 range of constructors that can be used are limited. If types <code class="computeroutput"><span class="identifier">T1</span></code> and <code class="computeroutput"><span class="identifier">T2</span></code>
113 are the same type, then there is only one version of the single-argument constructor,
114 and this constructor initialises both values in the pair to the passed value.
117 Note that if either member is a POD type, then that member is not zero-initialized
118 by the <code class="computeroutput"><span class="identifier">compressed_pair</span></code> default
119 constructor: it's up to you to supply an initial value for these types if you
120 want them to have a default value.
123 Note that <code class="computeroutput"><span class="identifier">compressed_pair</span></code> can
124 not be instantiated if either of the template arguments is a union type, unless
125 there is compiler support for <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_union</span></code>,
126 or if <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_union</span></code> is specialised for the union type.
129 Finally, a word of caution for Visual C++ 6 users: if either argument is an
130 empty type, then assigning to that member will produce memory corruption, unless
131 the empty type has a "do nothing" assignment operator defined. This
132 is due to a bug in the way VC6 generates implicit assignment operators.
135 <div class="section">
136 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
137 <a name="compressed_pair.acknowledgments"></a><a class="link" href="compressed_pair.html#compressed_pair.acknowledgments" title="Acknowledgments">Acknowledgments</a>
138 </h2></div></div></div>
140 Based on contributions by Steve Cleary, Beman Dawes, Howard Hinnant and John
144 Maintained by <a href="mailto:john%40johnmaddock.co.uk" target="_top">John Maddock</a>.
148 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
149 <td align="left"><p><small>Last revised: December 10, 2019 at 00:21:47 GMT</small></p></td>
150 <td align="right"><div class="copyright-footer"></div></td>
153 <div class="spirit-nav"></div>