• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Distributed under the Boost
2.. Software License, Version 1.0. (See accompanying
3.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5++++++++++++++++++++++++++++++++++++++++
6 ``pointee`` and ``indirect_reference``
7++++++++++++++++++++++++++++++++++++++++
8
9:Author: David Abrahams
10:Contact: dave@boost-consulting.com
11:organization: `Boost Consulting`_
12:date: $Date$
13:copyright: Copyright David Abrahams 2004.
14
15.. _`Boost Consulting`: http://www.boost-consulting.com
16
17:abstract: Provides the capability to deduce the referent types of
18  pointers, smart pointers and iterators in generic code.
19
20Overview
21========
22
23Have you ever wanted to write a generic function that can operate
24on any kind of dereferenceable object?  If you have, you've
25probably run into the problem of how to determine the type that the
26object "points at":
27
28.. parsed-literal::
29
30   template <class Dereferenceable>
31   void f(Dereferenceable p)
32   {
33       *what-goes-here?* value = \*p;
34       ...
35   }
36
37
38``pointee``
39-----------
40
41It turns out to be impossible to come up with a fully-general
42algorithm to do determine *what-goes-here* directly, but it is
43possible to require that ``pointee<Dereferenceable>::type`` is
44correct. Naturally, ``pointee`` has the same difficulty: it can't
45determine the appropriate ``::type`` reliably for all
46``Dereferenceable``\ s, but it makes very good guesses (it works
47for all pointers, standard and boost smart pointers, and
48iterators), and when it guesses wrongly, it can be specialized as
49necessary::
50
51  namespace boost
52  {
53    template <class T>
54    struct pointee<third_party_lib::smart_pointer<T> >
55    {
56        typedef T type;
57    };
58  }
59
60``indirect_reference``
61----------------------
62
63``indirect_reference<T>::type`` is rather more specialized than
64``pointee``, and is meant to be used to forward the result of
65dereferencing an object of its argument type.  Most dereferenceable
66types just return a reference to their pointee, but some return
67proxy references or return the pointee by value.  When that
68information is needed, call on ``indirect_reference``.
69
70Both of these templates are essential to the correct functioning of
71|indirect_iterator|_.
72
73.. |indirect_iterator| replace:: ``indirect_iterator``
74.. _indirect_iterator: indirect_iterator.html
75
76Reference
77=========
78
79``pointee``
80-----------
81
82.. include:: pointee_ref.rst
83
84``indirect_reference``
85----------------------
86
87.. include:: indirect_reference_ref.rst
88
89