1 | <?xml version="1.0" encoding="utf-8"?> |
---|
2 | <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" |
---|
3 | "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd"> |
---|
4 | <library name="Ref" dirname="ref" id="ref" last-revision="$Date: 2006/11/10 18:27:05 $"> |
---|
5 | <libraryinfo> |
---|
6 | <author> |
---|
7 | <firstname>Jaakko</firstname> |
---|
8 | <surname>Järvi</surname> |
---|
9 | </author> |
---|
10 | <author> |
---|
11 | <firstname>Peter</firstname> |
---|
12 | <surname>Dimov</surname> |
---|
13 | </author> |
---|
14 | <author> |
---|
15 | <firstname>Douglas</firstname> |
---|
16 | <surname>Gregor</surname> |
---|
17 | </author> |
---|
18 | <author> |
---|
19 | <firstname>Dave</firstname> |
---|
20 | <surname>Abrahams</surname> |
---|
21 | </author> |
---|
22 | |
---|
23 | <copyright> |
---|
24 | <year>1999</year> |
---|
25 | <year>2000</year> |
---|
26 | <holder>Jaakko Järvi</holder> |
---|
27 | </copyright> |
---|
28 | |
---|
29 | <copyright> |
---|
30 | <year>2001</year> |
---|
31 | <year>2002</year> |
---|
32 | <holder>Peter Dimov</holder> |
---|
33 | </copyright> |
---|
34 | |
---|
35 | <copyright> |
---|
36 | <year>2002</year> |
---|
37 | <holder>David Abrahams</holder> |
---|
38 | </copyright> |
---|
39 | |
---|
40 | <legalnotice> |
---|
41 | <para>Subject to the Boost Software License, Version 1.0. See |
---|
42 | accompanying file <filename>LICENSE_1_0.txt</filename> or copy at |
---|
43 | <ulink url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>. |
---|
44 | </para> |
---|
45 | </legalnotice> |
---|
46 | |
---|
47 | <librarypurpose>A utility library for passing references to generic functions</librarypurpose> |
---|
48 | <librarycategory name="category:higher-order"/> |
---|
49 | </libraryinfo> |
---|
50 | |
---|
51 | <title>Boost.Ref</title> |
---|
52 | |
---|
53 | <section id="ref.intro"> |
---|
54 | <title>Introduction</title> |
---|
55 | |
---|
56 | <using-namespace name="boost"/> |
---|
57 | |
---|
58 | <para>The Ref library is a small library that is useful for passing |
---|
59 | references to function templates (algorithms) that would usually |
---|
60 | take copies of their arguments. It defines the class template |
---|
61 | <code><classname>boost::reference_wrapper<T></classname></code>, |
---|
62 | the two functions |
---|
63 | <code><functionname>boost::ref</functionname></code> and |
---|
64 | <code><functionname>boost::cref</functionname></code> that return |
---|
65 | instances of <code>boost::reference_wrapper<T></code>, and the |
---|
66 | two traits classes |
---|
67 | <code><classname>boost::is_reference_wrapper<T></classname></code> |
---|
68 | and |
---|
69 | <code><classname>boost::unwrap_reference<T></classname></code>.</para> |
---|
70 | |
---|
71 | <para>The purpose of |
---|
72 | <code>boost::reference_wrapper<T></code> is to |
---|
73 | contain a reference to an object of type T. It is primarily used to |
---|
74 | "feed" references to function templates (algorithms) that take their |
---|
75 | parameter by value.</para> |
---|
76 | |
---|
77 | <para>To support this usage, |
---|
78 | <code>boost::reference_wrapper<T></code> provides an implicit |
---|
79 | conversion to <code>T&</code>. This usually allows the function |
---|
80 | templates to work on references unmodified.</para> |
---|
81 | |
---|
82 | <para><code>boost::reference_wrapper<T></code> is |
---|
83 | both CopyConstructible and Assignable (ordinary references are not |
---|
84 | Assignable).</para> |
---|
85 | |
---|
86 | <para>The expression <code>boost::ref(x)</code> |
---|
87 | returns a |
---|
88 | <code>boost::reference_wrapper<X>(x)</code> where X |
---|
89 | is the type of x. Similarly, |
---|
90 | <code>boost::cref(x)</code> returns a |
---|
91 | <code>boost::reference_wrapper<X const>(x)</code>.</para> |
---|
92 | |
---|
93 | <para>The expression |
---|
94 | <code>boost::is_reference_wrapper<T>::value</code> |
---|
95 | is true if T is a <code>reference_wrapper</code>, and |
---|
96 | false otherwise.</para> |
---|
97 | |
---|
98 | <para>The type-expression |
---|
99 | <code>boost::unwrap_reference<T>::type</code> is T::type if T |
---|
100 | is a <code>reference_wrapper</code>, T otherwise.</para> |
---|
101 | </section> |
---|
102 | |
---|
103 | <library-reference> |
---|
104 | <header name="boost/ref.hpp"> |
---|
105 | <namespace name="boost"> |
---|
106 | <class name="reference_wrapper"> |
---|
107 | <template> |
---|
108 | <template-type-parameter name="T"/> |
---|
109 | </template> |
---|
110 | <purpose> |
---|
111 | Contains a reference to an object of type |
---|
112 | <computeroutput>T</computeroutput>. |
---|
113 | </purpose> |
---|
114 | |
---|
115 | <description> |
---|
116 | <para><computeroutput><classname>reference_wrapper</classname></computeroutput> |
---|
117 | is primarily used to "feed" references to function templates |
---|
118 | (algorithms) that take their parameter by value. It provides |
---|
119 | an implicit conversion to |
---|
120 | <computeroutput>T&</computeroutput>, which usually allows |
---|
121 | the function templates to work on references |
---|
122 | unmodified.</para> |
---|
123 | </description> |
---|
124 | |
---|
125 | <typedef name="type"><type>T</type></typedef> |
---|
126 | |
---|
127 | <constructor specifiers="explicit"> |
---|
128 | <parameter name="t"> |
---|
129 | <paramtype>T&</paramtype> |
---|
130 | </parameter> |
---|
131 | |
---|
132 | <effects><simpara>Constructs a |
---|
133 | <computeroutput><classname>reference_wrapper</classname></computeroutput> |
---|
134 | object that stores a reference to |
---|
135 | <computeroutput>t</computeroutput>.</simpara></effects> |
---|
136 | |
---|
137 | <throws><simpara>Does not throw.</simpara></throws> |
---|
138 | </constructor> |
---|
139 | |
---|
140 | <method-group name="access"> |
---|
141 | <method name="conversion-operator" cv="const"> |
---|
142 | <type>T&</type> |
---|
143 | <returns><simpara>The stored reference.</simpara></returns> |
---|
144 | <throws><simpara>Does not throw.</simpara></throws> |
---|
145 | </method> |
---|
146 | |
---|
147 | <method name="get" cv="const"> |
---|
148 | <type>T&</type> |
---|
149 | <returns><simpara>The stored reference.</simpara></returns> |
---|
150 | <throws><simpara>Does not throw.</simpara></throws> |
---|
151 | </method> |
---|
152 | |
---|
153 | <method name="get_pointer" cv="const"> |
---|
154 | <type>T*</type> |
---|
155 | <returns><simpara>A pointer to the object referenced by the stored reference.</simpara></returns> |
---|
156 | <throws><simpara>Does not throw.</simpara></throws> |
---|
157 | </method> |
---|
158 | </method-group> |
---|
159 | |
---|
160 | <free-function-group name="constructors"> |
---|
161 | <function name="ref"> |
---|
162 | <type>reference_wrapper<T></type> |
---|
163 | <parameter name="t"> |
---|
164 | <paramtype>T&</paramtype> |
---|
165 | </parameter> |
---|
166 | |
---|
167 | <returns><simpara><computeroutput><classname>reference_wrapper</classname><T>(t)</computeroutput></simpara></returns> |
---|
168 | |
---|
169 | <throws><simpara>Does not throw.</simpara></throws> |
---|
170 | </function> |
---|
171 | |
---|
172 | <function name="cref"> |
---|
173 | <type>reference_wrapper<T const></type> |
---|
174 | <parameter name="t"> |
---|
175 | <paramtype>T const&</paramtype> |
---|
176 | </parameter> |
---|
177 | |
---|
178 | <returns><simpara><computeroutput><classname>reference_wrapper</classname><T const>(t)</computeroutput></simpara></returns> |
---|
179 | |
---|
180 | <throws><simpara>Does not throw.</simpara></throws> |
---|
181 | </function> |
---|
182 | </free-function-group> |
---|
183 | </class> |
---|
184 | |
---|
185 | <class name="is_reference_wrapper"> |
---|
186 | <template> |
---|
187 | <template-type-parameter name="T"/> |
---|
188 | </template> |
---|
189 | |
---|
190 | <purpose>Determine if a type <computeroutput>T</computeroutput> is an instantiation of <computeroutput><classname>reference_wrapper</classname></computeroutput>.</purpose> |
---|
191 | |
---|
192 | <description> |
---|
193 | <para>The <computeroutput>value</computeroutput> static |
---|
194 | constant will be <computeroutput>true</computeroutput> iff the |
---|
195 | type <computeroutput>T</computeroutput> is a specialization of |
---|
196 | <computeroutput><classname>reference_wrapper</classname></computeroutput>.</para> |
---|
197 | </description> |
---|
198 | |
---|
199 | <static-constant name="value"> |
---|
200 | <type>bool</type> |
---|
201 | <default><emphasis>unspecified</emphasis></default> |
---|
202 | </static-constant> |
---|
203 | </class> |
---|
204 | |
---|
205 | <class name="unwrap_reference"> |
---|
206 | <template> |
---|
207 | <template-type-parameter name="T"/> |
---|
208 | </template> |
---|
209 | |
---|
210 | <purpose>Find the type in a <computeroutput><classname>reference_wrapper</classname></computeroutput>.</purpose> |
---|
211 | |
---|
212 | <description> |
---|
213 | <para>The typedef <computeroutput>type</computeroutput> is |
---|
214 | <computeroutput>T::type</computeroutput> if |
---|
215 | <computeroutput>T</computeroutput> is a |
---|
216 | <computeroutput><classname>reference_wrapper</classname></computeroutput>, |
---|
217 | <computeroutput>T</computeroutput> otherwise.</para> |
---|
218 | </description> |
---|
219 | |
---|
220 | <typedef name="type"><type><emphasis>unspecified</emphasis></type></typedef> |
---|
221 | </class> |
---|
222 | </namespace> |
---|
223 | </header> |
---|
224 | </library-reference> |
---|
225 | |
---|
226 | <section id="ref.ack"> |
---|
227 | <title>Acknowledgements</title> |
---|
228 | |
---|
229 | <using-namespace name="boost"/> |
---|
230 | |
---|
231 | <para><functionname>ref</functionname> and <functionname>cref</functionname> |
---|
232 | were originally part of the <libraryname>Tuple</libraryname> library |
---|
233 | by Jaakko Järvi. They were "promoted to boost:: status" by |
---|
234 | Peter Dimov because they are generally useful. Douglas Gregor and |
---|
235 | Dave Abrahams contributed |
---|
236 | <classname>is_reference_wrapper</classname> and |
---|
237 | <classname>unwrap_reference</classname>.</para> |
---|
238 | </section> |
---|
239 | |
---|
240 | </library> |
---|