boost_ptr_container 0.1.0

Boost C++ library boost_ptr_container packaged using Zanbil
Documentation
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
++++++++++++++++++++++++++++++++++
 |Boost| Pointer Container Library
++++++++++++++++++++++++++++++++++
 
.. |Boost| image:: boost.png

Class ``reversible_ptr_container``
------------------------------------

This class is not a real class that can be found in the library. 
Its purpose is to present the general interface of all the pointer containers.

**Hierarchy:**

- ``reversible_ptr_container``

  - `ptr_sequence_adapter <ptr_sequence_adapter.html>`_

    - `ptr_vector <ptr_vector.html>`_
    - `ptr_list <ptr_list.html>`_ 
    - `ptr_deque <ptr_deque.html>`_
    - `ptr_array <ptr_array.html>`_
    
  - `associative_ptr_container <associative_ptr_container.html>`_ 
  
    - `ptr_set_adapter <ptr_set_adapter.html>`_
    - `ptr_multiset_adapter <ptr_multiset_adapter.html>`_
    - `ptr_map_adapter <ptr_map_adapter.html>`_
    - `ptr_multi_map_adapter <ptr_multimap_adapter.html>`_

      - `ptr_set <ptr_set.html>`_
      - `ptr_multi_set <ptr_multiset.html>`_ 
      - `ptr_map <ptr_map.html>`_
      - `ptr_multimap <ptr_multimap.html>`_

**Navigate:**

- `home <ptr_container.html>`_
- `reference <reference.html>`_

**synopsis:**

.. parsed-literal:: 
            
        namespace boost
        {      
            template
            < 
                class T, 
                class CloneAllocator,
                class VoidPtrContainer
            >
            class reversible_ptr_container 
            {
            public: // `typedefs`_
                typedef  T*                                           value_type;
                typedef  T&                                           reference;
                typedef  const T&                                     const_reference;
                typedef  *implementation defined*                       iterator;
                typedef  *implementation defined*                       const_iterator;
                typedef  typename VoidPtrContainer::differnce_type    difference_type; 
                typedef  typename VoidPtrContainer::size_type         size_type;
                typedef  typename VoidPtrContainer::allocator_type    allocator_type;
                typedef  *implementation defined*                       reverse_iterator;
                typedef  *implementation defined*                       const_reverse_iterator;
                typedef  *implementation defined*                       auto_type;
            
            public: // `construct/copy/destroy`_
                reversible_ptr_container();
                explicit reversible_ptr_container( const reversible_ptr_container& r );                
                template< class Derived >
                explicit reversible_ptr_container( const reversible_ptr_container<Derived>& r );
                explicit reversible_ptr_container( compatible-smart-ptr<reversible_ptr_container> r );
                template< class InputIterator >
                reversible_ptr_container( InputIterator first, InputIterator last );
                
                ~reversible_ptr_container();

                reversible_ptr_container&  operator=( const reversible_ptr_container& r );
                template<class Derived>
                reversible_ptr_container&  operator=( const reversible_ptr_container<Derived>& r );
                reversible_ptr_container&  operator=( compatible-smart-ptr<reversible_ptr_container> r );
                allocator_type             get_allocator() const;                                      
            
            public: // `iterators`_
                iterator                begin();
                const_iterator          begin() const;
                iterator                end();
                const_iterator          end() const;
                reverse_iterator        rbegin();
                const_reverse_iterator  rbegin() const;
                reverse_iterator        rend();
                const_reverse_iterator  rend() const;
                
            public: // `capacity`_
                size_type  size() const;
                size_type  max_size() const;
                bool       empty() const;       
            
            public: // `modifiers`_
                void                     swap( reversible_ptr_container& r );
                void                     clear():
                VoidPtrContainer&        base();
                const VoidPtrContainer&  base() const;
            
            public: // `pointer container requirements`_
                auto_type                                replace( iterator position, T* x );
                template< class U >
                auto_type                                replace( iterator position, compatible-smart-ptr<U> x );    
                compatible-smart-ptr<reversible_ptr_container>  clone() const;    
                compatible-smart-ptr<reversible_ptr_container>  release();
                auto_type                                release( iterator position );
                            
            }; //  class 'reversible_ptr_container'

            // `comparison`_            
            template < class T, class CA, class VPC >
            bool operator==( const reversible_ptr_container<T,CA,VPC>& x,
                             const reversible_ptr_container<T,CA,VPC>& y);
            
            template < class T, class CA, class VPC  >
            bool operator<( const reversible_ptr_container<T,CA,VPC>& x,
                            const reversible_ptr_container<T,CA,VPC>& y);
            
            template < class T, class CA, class VPC  >
            bool operator!=( const reversible_ptr_container<T,CA,VPC>& x,
                             const reversible_ptr_container<T,CA,VPC>& y);
            
            template < class T,  class CA, class VPC >
            bool operator>( const reversible_ptr_container<T,CA,VPC>& x,
                            const reversible_ptr_container<T,CA,VPC>& y);
            
            template < class T,  class CA, class VPC >
            bool operator>=( const reversible_ptr_container<T,CA,VPC>& x,
                             const reversible_ptr_container<T,CA,VPC>& y);
            
            template < class T,  class CA, class VPC >
            bool operator<=( const reversible_ptr_container<T,CA,VPC>& x,
                             const reversible_ptr_container<T,CA,VPC>& y);

            template< class T,  class CA, class VPC  >
            void swap( reversible_ptr_container<T,CA,VPC>& x,
                       reversible_ptr_container<T,CA,VPC>& y );

            // cloneability_
            template< class T,  class CA, class VPC >
            reversible_ptr_container<T,CA,VPC>*
            new_clone( const reversible_ptr_container<T,CA,VPC>& r );

            // `null predicate`_
            template< class Iterator >
            bool is_null( Iterator i );
            
            // `serialization`_
            template<class Archive, class T, class CA, class VPC>
            void serialize( Archive& ar, reversible_ptr_container<T,C�,VPC>& c, const unsigned int version );


        } // namespace 'boost'



Semantics
---------

.. _`typedefs`:

Semantics: typedefs
^^^^^^^^^^^^^^^^^^^

Notice how these two types differ:


- ``typedef T* value_type;``

    - notice this has pointer type

- ``typedef T& reference;``

    - notice this is not a pointer type

This is done to be able to add pointers directly
to the container, but to hide the pointers externally.

..
        - ``typedef *implementation defined* object_type;``
        - this is ``T`` for sequences and sets
        - this is ``std::pair<const Key, void*>`` for maps

Also notice that

- ``typedef ... iterator``

allows one to iterate over ``T&`` objects, not ``T*``.
Note that::

    iterator i = ...;
    i.base();

returns an iterator that allows one to iterate over ``void*``
elements (*this is very rarely needed and you should not use the
functionality unless you know what you are doing*).

- ``typedef ... auto_type``

This declaration hides a pointer pointer type. You can rely on the following
operations 

.. parsed-literal:: 

    T* operator->() const;
    T& operator*() const;
    T* release();
    ~auto_type();
    operator *implementation-defined bool*\ ();


The destructor will delete the stored object *using the clone allocator of the container*
(this explains why we cannot use ``std::auto_ptr<T>`` nor ``std::unique_ptr<T>``). It might help to
think it is just a ``compatible-smart-ptr<T>``. You can also return
the pointer from a function or assign it to another pointer via the ``move()``
function

.. parsed-literal::

    auto_type ptr   = ...;
    auto_type other = boost::ptr_container::move( ptr );
    return boost::ptr_container::move( other );

.. _construct/copy/destroy:

Semantics: construct/copy/destroy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``reversible_ptr_container();``

    - Effects: Constructs an empty container

    - Postconditions: ``size() == 0``

..
        - ``reversible_ptr_container( size_type n, const T& x );``

        - Effects: Constructs a container with ``n`` clones of ``x``

        - Postconditions: ``size() == n``
    
- ``explicit reversible_ptr_container( const reversible_ptr_container& r );``

    - Effects: Constructs a container by cloning all elements of ``r``
    
- ``template< class Derived > explicit reversible_ptr_container( const reversible_ptr_container<Derived>& r );``

    - Effects: Constructs a container by cloning all elements of ``r``
    
    - Requirements: ``Derived`` is derived from ``T`` 

- ``explicit reversible_ptr_container( compatible-smart-ptr< reversible_ptr_container > r );``

    - Effects: Constructs a container by taking ownership of the supplied pointers


- ``template< class InputIterator >``
  ``reversible_ptr_container( InputIterator first, InputIterator last );``

    - Requirements: ``(first,last]`` is a valid range

    - Effects: Constructs a container with a cloned range of ``(first,last]``

    - Postconditions: ``size() == std::distance( first, last )``

- ``~reversible_ptr_container();``

    - Effects: Deletes the stored objects via the clone allocator

    - Throws: Nothing

- ``reversible_ptr_container& operator=( const reversible_ptr_container& r );``

    - Effects: Assigns a clone of ``r``
    
    - Exception safety: strong guarantee
    
- ``template<class Derived> reversible_ptr_container& operator=( const reversible_ptr_container<Derived>& r );``

    - Effects: Assigns a clone of ``r``
    
    - Requirements: ``Derived`` is derived from ``T`` 
    
    - Exception safety: Strong guarantee

- ``reversible_ptr_container& operator=( compatible-smart-ptr<reversible_ptr_container> r );``

    - Effects: Deletes the stored objects and then takes ownership of the supplied pointers

    - Throws: Nothing

- ``allocator_type get_allocator() const;``

    - Effects: Returns a copy of the allocator of the container object


.. _iterators:

Semantics: iterators
^^^^^^^^^^^^^^^^^^^^

**See also:** `iterator invalidation <conventions.html#iterators-are-invalidated-as-in-the-corresponding-standard-container>`_

- ``iterator begin();``
- ``const_iterator begin() const;``

    - Effects: Returns a mutable/non-mutable iterator with ``value_type T``

    - Throws: Nothing

- ``iterator end();``
- ``const_iterator end() const;``

    - Effects: Returns a mutable/non-mutable iterator with ``value_type T``

    - Throws: Nothing

- ``reverse_iterator rbegin();``

- ``const_reverse_iterator rbegin() const;``

    - Effects: Returns a mutable/non-mutable reverse iterator with ``value_type T``

    - Throws: Nothing

- ``reverse_iterator rend();``

- ``const_reverse_iterator rend() const;``

    - Effects: Returns a mutable/non-mutable reverse iterator with ``value_type T``

    - Throws: Nothing

.. _capacity: 

Semantics: capacity
^^^^^^^^^^^^^^^^^^^

- ``size_type size() const;``

    - Effects: Returns the number of stored elements

    - Throws: Nothing

- ``size_type max_size() const;``

    - Effects: Returns the maximum number of stored elements

    - Throws: Nothing

- ``bool empty() const;``

    - Effects: Returns whether the container is empty or not

    - Throws: Nothing


.. _modifiers:

Semantics: modifiers
^^^^^^^^^^^^^^^^^^^^

- ``void swap( reversible_ptr_container& r );``

    - Effects: Swaps the content of the two containers

    - Throws: Nothing

- ``void clear();``

    - Effects: Destroys all object of the container 

    - Postconditions: ``empty() == true``

    - Throws: Nothing

- ``VoidPtrContainer& base();``

- ``const VoidPtrContainer& base() const;``

    - Returns: a reference to the wrapped container

.. _`pointer container requirements`:

Semantics: pointer container requirements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``auto_type replace( iterator position, T* x );``

    - Requirements: ``not empty() and x != 0``

    - Effects: returns the object pointed to by ``position`` and replaces it with ``x``.

    - Throws: ``bad_ptr_container_operation`` if the container is empty and ``bad_pointer`` if ``x == 0``.

    - Exception safety: Strong guarantee
    
- ``template< class U > auto_type replace( iterator position, compatible-smart-ptr<U> x );``

    - Effects: ``return replace( position, x.release() );``     

- ``compatible-smart-ptr< reversible_ptr_container > clone() const;``

    - Effects: Returns a deep copy of the container

    - Throws: ``std::bad_alloc`` if there is not enough memory to make a clone of the container

    - Complexity: Linear

- ``compatible-smart-ptr< reversible_ptr_container > release();``

    - Effects: Releases ownership of the container. This is a useful way of returning a container from a function.

    - Postconditions: ``empty() == true``

    - Throws: ``std::bad_alloc`` if the return value cannot be allocated

    - Exception safety: Strong guarantee

- ``auto_type release( iterator position );``

    - Requirements: ``not empty();``

    - Effects: Releases ownership of the pointer referred to by position

    - Postconditions: ``size()`` is one less 

    - Throws: ``bad_ptr_container_operation`` if the container is empty

    - Exception safety: Strong guarantee


.. _comparison:

Semantics: comparison
^^^^^^^^^^^^^^^^^^^^^

These functions compare the underlying range of objects. 
So ::

        operation( const ptr_container& l, const ptr_container& r );

has the effect one would expect of normal standard containers. Hence
objects are compared and not the pointers to objects.

.. _`cloneability`:

Semantics: cloneability
^^^^^^^^^^^^^^^^^^^^^^^

-  ``template< class T, class CloneAllocator >
   reversible_ptr_container<T,CA,VPC>* 
   new_clone( const reversible_ptr_container<T,CA,VPC>& r );``


    - Effects: ``return r.clone().release();``

    - Remarks: This function is only defined for concrete `pointer containers`_, but not for 
      `pointer container adapters`_.

.. _`pointer containers`: ptr_container.html#smart-containers
.. _`pointer container adapters`: ptr_container.html#smart-container-adapters

.. _`null predicate`:

Semantics: null predicate
^^^^^^^^^^^^^^^^^^^^^^^^^

- ``template< class Iterator > bool is_null( Iterator i );``

    - Requirements: ``i`` is a valid dereferencable iterator

    - Returns: ``*i.base() == 0;``

.. _`serialization`:

Semantics: serialization
^^^^^^^^^^^^^^^^^^^^^^^^

All containers can be serialized by means of
`Boost.Serialization`__. For an overview, see
`Serialization of Pointer Containers`_.

.. __: ../../serialization/index.html
.. _`Serialization of Pointer Containers`: reference.html#serialization

 ::
 
    template<class Archive, class T, class CA, class VPC>
    void serialize( Archive& ar, reversible_ptr_container<T,CA,VPC>& c, const unsigned int version );
            

- Effects: Saves or loads the container to/from the archive.

- Remarks: This function is called automatically be stream operators in
  Boost.Serialization
    
- Exception safety: Loading gives the basic guarantee


.. raw:: html 

        <hr/>

:Copyright:     Thorsten Ottosen 2004-2007. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).

__ http://www.boost.org/LICENSE_1_0.txt