Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/bind/doc/ref.xml @ 13

Last change on this file since 13 was 12, checked in by landauf, 17 years ago

added boost

File size: 8.3 KB
Line 
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: 2004/07/09 00:56:42 $">
5  <libraryinfo>
6    <author>
7      <firstname>Jaakko</firstname>
8      <surname>J&auml;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&auml;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>Permission to copy, use, modify, sell and distribute this
42      software is granted provided this copyright notice appears in
43      all copies.  This software is provided "as is" without express
44      or implied warranty, and with no claim as to its suitability for
45      any purpose.
46      </para>
47    </legalnotice>
48
49    <librarypurpose>A utility library for passing references to generic functions</librarypurpose>
50    <librarycategory name="category:higher-order"/>
51  </libraryinfo>
52
53<title>Boost.Ref</title>
54
55<section id="ref.intro">
56  <title>Introduction</title> 
57
58  <using-namespace name="boost"/>
59
60  <para>The Ref library is a small library that is useful for passing
61  references to function templates (algorithms) that would usually
62  take copies of their arguments. It defines the class template
63  <code><classname>boost::reference_wrapper&lt;T&gt;</classname></code>,
64  the two functions
65  <code><functionname>boost::ref</functionname></code> and
66  <code><functionname>boost::cref</functionname></code> that return
67  instances of <code>boost::reference_wrapper&lt;T&gt;</code>, and the
68  two traits classes
69  <code><classname>boost::is_reference_wrapper&lt;T&gt;</classname></code>
70  and
71  <code><classname>boost::unwrap_reference&lt;T&gt;</classname></code>.</para>
72
73  <para>The purpose of
74  <code>boost::reference_wrapper&lt;T&gt;</code> is to
75  contain a reference to an object of type T. It is primarily used to
76  "feed" references to function templates (algorithms) that take their
77  parameter by value.</para>
78
79  <para>To support this usage,
80  <code>boost::reference_wrapper&lt;T&gt;</code> provides an implicit
81  conversion to <code>T&amp;</code>. This usually allows the function
82  templates to work on references unmodified.</para>
83
84  <para><code>boost::reference_wrapper&lt;T&gt;</code> is
85  both CopyConstructible and Assignable (ordinary references are not
86  Assignable).</para>
87
88  <para>The expression <code>boost::ref(x)</code>
89  returns a
90  <code>boost::reference_wrapper&lt;X&gt;(x)</code> where X
91  is the type of x. Similarly,
92  <code>boost::cref(x)</code> returns a
93  <code>boost::reference_wrapper&lt;X const&gt;(x)</code>.</para>
94
95  <para>The expression
96  <code>boost::is_reference_wrapper&lt;T&gt;::value</code>
97  is true if T is a <code>reference_wrapper</code>, and
98  false otherwise.</para>
99
100  <para>The type-expression
101  <code>boost::unwrap_reference&lt;T&gt;::type</code> is T::type if T
102  is a <code>reference_wrapper</code>, T otherwise.</para>
103</section>
104
105<library-reference>
106<header name="boost/ref.hpp">
107  <namespace name="boost">
108    <class name="reference_wrapper">
109      <template>
110        <template-type-parameter name="T"/>
111      </template>
112      <purpose>
113        Contains a reference to an object of type
114        <computeroutput>T</computeroutput>.
115      </purpose>
116
117      <description>
118        <para><computeroutput><classname>reference_wrapper</classname></computeroutput>
119        is primarily used to "feed" references to function templates
120        (algorithms) that take their parameter by value.  It provides
121        an implicit conversion to
122        <computeroutput>T&amp;</computeroutput>, which usually allows
123        the function templates to work on references
124        unmodified.</para>
125      </description>
126
127      <typedef name="type"><type>T</type></typedef>
128
129      <constructor specifiers="explicit">
130        <parameter name="t">
131          <paramtype>T&amp;</paramtype>
132        </parameter>
133
134        <effects><simpara>Constructs a
135        <computeroutput><classname>reference_wrapper</classname></computeroutput>
136        object that stores a reference to
137        <computeroutput>t</computeroutput>.</simpara></effects>
138
139        <throws><simpara>Does not throw.</simpara></throws>
140      </constructor>   
141
142      <method-group name="access">
143        <method name="conversion-operator" cv="const">
144          <type>T&amp;</type>
145          <returns><simpara>The stored reference.</simpara></returns>
146          <throws><simpara>Does not throw.</simpara></throws>
147        </method>
148
149        <method name="get" cv="const">
150          <type>T&amp;</type>
151          <returns><simpara>The stored reference.</simpara></returns>
152          <throws><simpara>Does not throw.</simpara></throws>
153        </method>
154
155        <method name="get_pointer" cv="const">
156          <type>T*</type>
157          <returns><simpara>A pointer to the object referenced by the stored reference.</simpara></returns>
158          <throws><simpara>Does not throw.</simpara></throws>
159        </method>
160      </method-group>
161
162      <free-function-group name="constructors">
163        <function name="ref">
164          <type>reference_wrapper&lt;T&gt;</type>
165          <parameter name="t">
166            <paramtype>T&amp;</paramtype>
167          </parameter>
168
169          <returns><simpara><computeroutput><classname>reference_wrapper</classname>&lt;T&gt;(t)</computeroutput></simpara></returns>
170
171          <throws><simpara>Does not throw.</simpara></throws>
172        </function>
173
174        <function name="cref">
175          <type>reference_wrapper&lt;T const&gt;</type>
176          <parameter name="t">
177            <paramtype>T const&amp;</paramtype>
178          </parameter>
179
180          <returns><simpara><computeroutput><classname>reference_wrapper</classname>&lt;T const&gt;(t)</computeroutput></simpara></returns>
181
182          <throws><simpara>Does not throw.</simpara></throws>
183        </function>
184      </free-function-group>
185    </class>
186
187    <class name="is_reference_wrapper">
188      <template>
189        <template-type-parameter name="T"/>
190      </template>
191
192      <purpose>Determine if a type <computeroutput>T</computeroutput> is an instantiation of <computeroutput><classname>reference_wrapper</classname></computeroutput>.</purpose>
193
194      <description>
195        <para>The <computeroutput>value</computeroutput> static
196        constant will be <computeroutput>true</computeroutput> iff the
197        type <computeroutput>T</computeroutput> is a specialization of
198        <computeroutput><classname>reference_wrapper</classname></computeroutput>.</para>
199      </description>
200
201      <static-constant name="value">
202        <type>bool</type>
203        <default><emphasis>unspecified</emphasis></default>
204      </static-constant>
205    </class>
206
207    <class name="unwrap_reference">
208      <template>
209        <template-type-parameter name="T"/>
210      </template>
211 
212      <purpose>Find the type in a <computeroutput><classname>reference_wrapper</classname></computeroutput>.</purpose>
213
214      <description>
215        <para>The typedef <computeroutput>type</computeroutput> is
216        <computeroutput>T::type</computeroutput> if
217        <computeroutput>T</computeroutput> is a
218        <computeroutput><classname>reference_wrapper</classname></computeroutput>,
219        <computeroutput>T</computeroutput> otherwise.</para>
220      </description>
221
222      <typedef name="type"><type><emphasis>unspecified</emphasis></type></typedef>
223    </class>
224  </namespace>
225</header>
226</library-reference>
227
228<section id="ref.ack">
229  <title>Acknowledgements</title>
230
231  <using-namespace name="boost"/> 
232
233  <para><functionname>ref</functionname> and <functionname>cref</functionname>
234  were originally part of the <libraryname>Tuple</libraryname> library
235  by Jaakko J&auml;rvi. They were "promoted to boost:: status" by
236  Peter Dimov because they are generally useful.  Douglas Gregor and
237  Dave Abrahams contributed
238  <classname>is_reference_wrapper</classname> and
239  <classname>unwrap_reference</classname>.</para>
240</section>
241
242</library>
Note: See TracBrowser for help on using the repository browser.