Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/iterator/doc/pointee.html @ 12

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

added boost

  • Property svn:executable set to *
File size: 8.9 KB
Line 
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<meta name="generator" content="Docutils 0.3.8: http://docutils.sourceforge.net/" />
7<title>pointee and indirect_reference</title>
8<meta name="author" content="David Abrahams" />
9<meta name="organization" content="Boost Consulting" />
10<meta name="date" content="2005-02-27" />
11<meta name="copyright" content="Copyright David Abrahams 2004." />
12<link rel="stylesheet" href="default.css" type="text/css" />
13</head>
14<body>
15<div class="document" id="pointee-and-indirect-reference">
16<h1 class="title"><tt class="docutils literal"><span class="pre">pointee</span></tt> and <tt class="docutils literal"><span class="pre">indirect_reference</span></tt></h1>
17<table class="docinfo" frame="void" rules="none">
18<col class="docinfo-name" />
19<col class="docinfo-content" />
20<tbody valign="top">
21<tr><th class="docinfo-name">Author:</th>
22<td>David Abrahams</td></tr>
23<tr><th class="docinfo-name">Contact:</th>
24<td><a class="first last reference" href="mailto:dave&#64;boost-consulting.com">dave&#64;boost-consulting.com</a></td></tr>
25<tr><th class="docinfo-name">Organization:</th>
26<td><a class="first last reference" href="http://www.boost-consulting.com">Boost Consulting</a></td></tr>
27<tr><th class="docinfo-name">Date:</th>
28<td>2005-02-27</td></tr>
29<tr><th class="docinfo-name">Copyright:</th>
30<td>Copyright David Abrahams 2004.</td></tr>
31</tbody>
32</table>
33<table class="docutils field-list" frame="void" rules="none">
34<col class="field-name" />
35<col class="field-body" />
36<tbody valign="top">
37<tr class="field"><th class="field-name">abstract:</th><td class="field-body">Provides the capability to deduce the referent types of
38pointers, smart pointers and iterators in generic code.</td>
39</tr>
40</tbody>
41</table>
42<div class="section" id="overview">
43<h1><a name="overview">Overview</a></h1>
44<p>Have you ever wanted to write a generic function that can operate
45on any kind of dereferenceable object?  If you have, you've
46probably run into the problem of how to determine the type that the
47object &quot;points at&quot;:</p>
48<pre class="literal-block">
49template &lt;class Dereferenceable&gt;
50void f(Dereferenceable p)
51{
52    <em>what-goes-here?</em> value = *p;
53    ...
54}
55</pre>
56<div class="section" id="pointee">
57<h2><a name="pointee"><tt class="docutils literal"><span class="pre">pointee</span></tt></a></h2>
58<p>It turns out to be impossible to come up with a fully-general
59algorithm to do determine <em>what-goes-here</em> directly, but it is
60possible to require that <tt class="docutils literal"><span class="pre">pointee&lt;Dereferenceable&gt;::type</span></tt> is
61correct. Naturally, <tt class="docutils literal"><span class="pre">pointee</span></tt> has the same difficulty: it can't
62determine the appropriate <tt class="docutils literal"><span class="pre">::type</span></tt> reliably for all
63<tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>s, but it makes very good guesses (it works
64for all pointers, standard and boost smart pointers, and
65iterators), and when it guesses wrongly, it can be specialized as
66necessary:</p>
67<pre class="literal-block">
68namespace boost
69{
70  template &lt;class T&gt;
71  struct pointee&lt;third_party_lib::smart_pointer&lt;T&gt; &gt;
72  {
73      typedef T type;
74  };
75}
76</pre>
77</div>
78<div class="section" id="indirect-reference">
79<h2><a name="indirect-reference"><tt class="docutils literal"><span class="pre">indirect_reference</span></tt></a></h2>
80<p><tt class="docutils literal"><span class="pre">indirect_reference&lt;T&gt;::type</span></tt> is rather more specialized than
81<tt class="docutils literal"><span class="pre">pointee</span></tt>, and is meant to be used to forward the result of
82dereferencing an object of its argument type.  Most dereferenceable
83types just return a reference to their pointee, but some return
84proxy references or return the pointee by value.  When that
85information is needed, call on <tt class="docutils literal"><span class="pre">indirect_reference</span></tt>.</p>
86<p>Both of these templates are essential to the correct functioning of
87<a class="reference" href="indirect_iterator.html"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt></a>.</p>
88</div>
89</div>
90<div class="section" id="reference">
91<h1><a name="reference">Reference</a></h1>
92<div class="section" id="id1">
93<h2><a name="id1"><tt class="docutils literal"><span class="pre">pointee</span></tt></a></h2>
94<!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
95<!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
96<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
97<pre class="literal-block">
98template &lt;class Dereferenceable&gt;
99struct pointee
100{
101    typedef /* see below */ type;
102};
103</pre>
104<table class="docutils field-list" frame="void" rules="none">
105<col class="field-name" />
106<col class="field-body" />
107<tbody valign="top">
108<tr class="field"><th class="field-name">Requires:</th><td class="field-body">For an object <tt class="docutils literal"><span class="pre">x</span></tt> of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>, <tt class="docutils literal"><span class="pre">*x</span></tt>
109is well-formed.  If <tt class="docutils literal"><span class="pre">++x</span></tt> is ill-formed it shall neither be
110ambiguous nor shall it violate access control, and
111<tt class="docutils literal"><span class="pre">Dereferenceable::element_type</span></tt> shall be an accessible type.
112Otherwise <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dereferenceable&gt;::value_type</span></tt> shall
113be well formed.  [Note: These requirements need not apply to
114explicit or partial specializations of <tt class="docutils literal"><span class="pre">pointee</span></tt>]</td>
115</tr>
116</tbody>
117</table>
118<p><tt class="docutils literal"><span class="pre">type</span></tt> is determined according to the following algorithm, where
119<tt class="docutils literal"><span class="pre">x</span></tt> is an object of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>:</p>
120<pre class="literal-block">
121if ( ++x is ill-formed )
122{
123    return ``Dereferenceable::element_type``
124}
125else if (``*x`` is a mutable reference to
126         std::iterator_traits&lt;Dereferenceable&gt;::value_type)
127{
128    return iterator_traits&lt;Dereferenceable&gt;::value_type
129}
130else
131{
132    return iterator_traits&lt;Dereferenceable&gt;::value_type const
133}
134</pre>
135</div>
136<div class="section" id="id2">
137<h2><a name="id2"><tt class="docutils literal"><span class="pre">indirect_reference</span></tt></a></h2>
138<!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
139<!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
140<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
141<pre class="literal-block">
142template &lt;class Dereferenceable&gt;
143struct indirect_reference
144{
145    typedef /* see below */ type;
146};
147</pre>
148<table class="docutils field-list" frame="void" rules="none">
149<col class="field-name" />
150<col class="field-body" />
151<tbody valign="top">
152<tr class="field"><th class="field-name">Requires:</th><td class="field-body">For an object <tt class="docutils literal"><span class="pre">x</span></tt> of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>, <tt class="docutils literal"><span class="pre">*x</span></tt>
153is well-formed.  If <tt class="docutils literal"><span class="pre">++x</span></tt> is ill-formed it shall neither be
154ambiguous nor shall it violate access control, and
155<tt class="docutils literal"><span class="pre">pointee&lt;Dereferenceable&gt;::type&amp;</span></tt> shall be well-formed.
156Otherwise <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dereferenceable&gt;::reference</span></tt> shall
157be well formed.  [Note: These requirements need not apply to
158explicit or partial specializations of <tt class="docutils literal"><span class="pre">indirect_reference</span></tt>]</td>
159</tr>
160</tbody>
161</table>
162<p><tt class="docutils literal"><span class="pre">type</span></tt> is determined according to the following algorithm, where
163<tt class="docutils literal"><span class="pre">x</span></tt> is an object of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>:</p>
164<pre class="literal-block">
165if ( ++x is ill-formed )
166    return ``pointee&lt;Dereferenceable&gt;::type&amp;``
167else
168    std::iterator_traits&lt;Dereferenceable&gt;::reference
169</pre>
170</div>
171</div>
172</div>
173<hr class="docutils footer" />
174<div class="footer">
175<a class="reference" href="pointee.rst">View document source</a>.
176Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
177</div>
178</body>
179</html>
Note: See TracBrowser for help on using the repository browser.