File: utilities.qbk

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (224 lines) | stat: -rw-r--r-- 6,586 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

[section:utilities Iterator Utilities]

[section:utilities_traits Traits]

[h2 Overview]

Have you ever wanted to write a generic function that can operate
on any kind of dereferenceable object?  If you have, you've
probably run into the problem of how to determine the type that the
object "points at":

   template <class Dereferenceable>
   void f(Dereferenceable p)
   {
       *what-goes-here?* value = \*p;
       ...
   }


[h2 `pointee`]

It turns out to be impossible to come up with a fully-general
algorithm to do determine *what-goes-here* directly, but it is
possible to require that `pointee<Dereferenceable>::type` is
correct. Naturally, `pointee` has the same difficulty: it can't
determine the appropriate `::type` reliably for all
`Dereferenceable`\ s, but it makes very good guesses (it works
for all pointers, standard and boost smart pointers, and
iterators), and when it guesses wrongly, it can be specialized as
necessary:

  namespace boost
  {
    template <class T>
    struct pointee<third_party_lib::smart_pointer<T> >
    {
        typedef T type;
    };
  }

[h2 `indirect_reference`]

`indirect_reference<T>::type` is rather more specialized than
`pointee`, and is meant to be used to forward the result of
dereferencing an object of its argument type.  Most dereferenceable
types just return a reference to their pointee, but some return
proxy references or return the pointee by value.  When that
information is needed, call on `indirect_reference`.

Both of these templates are essential to the correct functioning of
[link indirecct `indirect_iterator`].

[h2 Reference]

[h3 `pointeee`]

  template <class Dereferenceable>
  struct pointee
  {
      typedef /* see below */ type;
  };

[*Requires:] For an object `x` of type `Dereferenceable`, `*x`
  is well-formed.  If `++x` is ill-formed it shall neither be
  ambiguous nor shall it violate access control, and
  `Dereferenceable::element_type` shall be an accessible type.
  Otherwise `iterator_traits<Dereferenceable>::value_type` shall
  be well formed. \[Note: These requirements need not apply to
  explicit or partial specializations of `pointee`\]

`type` is determined according to the following algorithm, where
`x` is an object of type `Dereferenceable`:

  if ( ++x is ill-formed )
  {
      return `Dereferenceable::element_type`
  }
  else if (`*x` is a mutable reference to
           std::iterator_traits<Dereferenceable>::value_type)
  {
      return iterator_traits<Dereferenceable>::value_type
  }
  else
  {
      return iterator_traits<Dereferenceable>::value_type const
  }

[h3 `indirect_reference`]

  template <class Dereferenceable>
  struct indirect_reference
  {
      typedef /* see below */ type;
  };

[*Requires:] For an object `x` of type `Dereferenceable`, `*x`
  is well-formed.  If `++x` is ill-formed it shall neither be
  ambiguous nor shall it violate access control, and
  `pointee<Dereferenceable>::type&` shall be well-formed.
  Otherwise `iterator_traits<Dereferenceable>::reference` shall
  be well formed.  \[Note: These requirements need not apply to
  explicit or partial specializations of `indirect_reference`\]

`type` is determined according to the following algorithm, where
`x` is an object of type `Dereferenceable`:

  if ( ++x is ill-formed )
      return `pointee<Dereferenceable>::type&`
  else
      std::iterator_traits<Dereferenceable>::reference


[endsect]

[section:utilities_testing Testing and Concept Checking]

The iterator concept checking classes provide a mechanism for a
template to report better error messages when a user instantiates
the template with a type that does not meet the requirements of the
template.

For an introduction to using concept checking classes, see
the documentation for the 
[@../../concept_check/index.html `boost::concept_check`] library.


[h2 Reference]

[h3 Iterator Access Concepts]

* |Readable|_ 
* |Writable|_ 
* |Swappable|_ 
* |Lvalue|_ 

[/ .. |Readable| replace:: *Readable Iterator* ]
[/ .. _Readable: ReadableIterator.html            ]
[/                                                ]
[/ .. |Writable| replace:: *Writable Iterator*    ]
[/ .. _Writable: WritableIterator.html            ]
[/                                                ]
[/ .. |Swappable| replace:: *Swappable Iterator*  ]
[/ .. _Swappable: SwappableIterator.html          ]
[/                                                ]
[/ .. |Lvalue| replace:: *Lvalue Iterator*        ]
[/ .. _Lvalue: LvalueIterator.html                ]


Iterator Traversal Concepts
...........................

* |Incrementable|_
* |SinglePass|_
* |Forward|_
* |Bidir|_
* |Random|_


[/ .. |Incrementable| replace:: *Incrementable Iterator* ]
[/ .. _Incrementable: IncrementableIterator.html         ]
[/                                                       ]
[/ .. |SinglePass| replace:: *Single Pass Iterator*      ]
[/ .. _SinglePass: SinglePassIterator.html               ]
[/                                                       ]
[/ .. |Forward| replace:: *Forward Traversal*            ]
[/ .. _Forward: ForwardTraversal.html                    ]
[/                                                       ]
[/ .. |Bidir| replace:: *Bidirectional Traversal*        ]
[/ .. _Bidir: BidirectionalTraversal.html                ]
[/                                                       ]
[/ .. |Random| replace:: *Random Access Traversal*       ]
[/ .. _Random: RandomAccessTraversal.html                ]



[h3 `iterator_concepts.hpp` Synopsis]

    namespace boost_concepts {

        // Iterator Access Concepts

        template <typename Iterator>
        class ReadableIteratorConcept;

        template <
            typename Iterator
          , typename ValueType = std::iterator_traits<Iterator>::value_type
        >
        class WritableIteratorConcept;

        template <typename Iterator>
        class SwappableIteratorConcept;

        template <typename Iterator>
        class LvalueIteratorConcept;

        // Iterator Traversal Concepts

        template <typename Iterator>
        class IncrementableIteratorConcept;

        template <typename Iterator>
        class SinglePassIteratorConcept;

        template <typename Iterator>
        class ForwardTraversalConcept;

        template <typename Iterator>
        class BidirectionalTraversalConcept;

        template <typename Iterator>
        class RandomAccessTraversalConcept;

        // Interoperability

        template <typename Iterator, typename ConstIterator>
        class InteroperableIteratorConcept;

    }

[endsect]

[endsect]