1 ++++++++++++++++++++++++++++++++++
2 |Boost| Pointer Container Library
3 ++++++++++++++++++++++++++++++++++
5 .. |Boost| image:: boost.png
7 Class ``reversible_ptr_container``
8 ------------------------------------
10 This class is not a real class that can be found in the library.
11 Its purpose is to present the general interface of all the pointer containers.
15 - ``reversible_ptr_container``
17 - `ptr_sequence_adapter <ptr_sequence_adapter.html>`_
19 - `ptr_vector <ptr_vector.html>`_
20 - `ptr_list <ptr_list.html>`_
21 - `ptr_deque <ptr_deque.html>`_
22 - `ptr_array <ptr_array.html>`_
24 - `associative_ptr_container <associative_ptr_container.html>`_
26 - `ptr_set_adapter <ptr_set_adapter.html>`_
27 - `ptr_multiset_adapter <ptr_multiset_adapter.html>`_
28 - `ptr_map_adapter <ptr_map_adapter.html>`_
29 - `ptr_multi_map_adapter <ptr_multimap_adapter.html>`_
31 - `ptr_set <ptr_set.html>`_
32 - `ptr_multi_set <ptr_multiset.html>`_
33 - `ptr_map <ptr_map.html>`_
34 - `ptr_multimap <ptr_multimap.html>`_
38 - `home <ptr_container.html>`_
39 - `reference <reference.html>`_
51 class VoidPtrContainer
53 class reversible_ptr_container
55 public: // `typedefs`_
56 typedef T* value_type;
58 typedef const T& const_reference;
59 typedef *implementation defined* iterator;
60 typedef *implementation defined* const_iterator;
61 typedef typename VoidPtrContainer::differnce_type difference_type;
62 typedef typename VoidPtrContainer::size_type size_type;
63 typedef typename VoidPtrContainer::allocator_type allocator_type;
64 typedef *implementation defined* reverse_iterator;
65 typedef *implementation defined* const_reverse_iterator;
66 typedef *implementation defined* auto_type;
68 public: // `construct/copy/destroy`_
69 reversible_ptr_container();
70 explicit reversible_ptr_container( const reversible_ptr_container& r );
71 template< class Derived >
72 explicit reversible_ptr_container( const reversible_ptr_container<Derived>& r );
73 explicit reversible_ptr_container( std::auto_ptr<reversible_ptr_container> r );
74 template< class InputIterator >
75 reversible_ptr_container( InputIterator first, InputIterator last );
77 ~reversible_ptr_container();
79 reversible_ptr_container& operator=( const reversible_ptr_container& r );
80 template<class Derived>
81 reversible_ptr_container& operator=( const reversible_ptr_container<Derived>& r );
82 reversible_ptr_container& operator=( std::auto_ptr<reversible_ptr_container> r );
83 allocator_type get_allocator() const;
85 public: // `iterators`_
87 const_iterator begin() const;
89 const_iterator end() const;
90 reverse_iterator rbegin();
91 const_reverse_iterator rbegin() const;
92 reverse_iterator rend();
93 const_reverse_iterator rend() const;
95 public: // `capacity`_
96 size_type size() const;
97 size_type max_size() const;
100 public: // `modifiers`_
101 void swap( reversible_ptr_container& r );
103 VoidPtrContainer& base();
104 const VoidPtrContainer& base() const;
106 public: // `pointer container requirements`_
107 auto_type replace( iterator position, T* x );
109 auto_type replace( iterator position, std::auto_ptr<U> x );
110 std::auto_ptr<reversible_ptr_container> clone() const;
111 std::auto_ptr<reversible_ptr_container> release();
112 auto_type release( iterator position );
114 }; // class 'reversible_ptr_container'
117 template < class T, class CA, class VPC >
118 bool operator==( const reversible_ptr_container<T,CA,VPC>& x,
119 const reversible_ptr_container<T,CA,VPC>& y);
121 template < class T, class CA, class VPC >
122 bool operator<( const reversible_ptr_container<T,CA,VPC>& x,
123 const reversible_ptr_container<T,CA,VPC>& y);
125 template < class T, class CA, class VPC >
126 bool operator!=( const reversible_ptr_container<T,CA,VPC>& x,
127 const reversible_ptr_container<T,CA,VPC>& y);
129 template < class T, class CA, class VPC >
130 bool operator>( const reversible_ptr_container<T,CA,VPC>& x,
131 const reversible_ptr_container<T,CA,VPC>& y);
133 template < class T, class CA, class VPC >
134 bool operator>=( const reversible_ptr_container<T,CA,VPC>& x,
135 const reversible_ptr_container<T,CA,VPC>& y);
137 template < class T, class CA, class VPC >
138 bool operator<=( const reversible_ptr_container<T,CA,VPC>& x,
139 const reversible_ptr_container<T,CA,VPC>& y);
141 template< class T, class CA, class VPC >
142 void swap( reversible_ptr_container<T,CA,VPC>& x,
143 reversible_ptr_container<T,CA,VPC>& y );
146 template< class T, class CA, class VPC >
147 reversible_ptr_container<T,CA,VPC>*
148 new_clone( const reversible_ptr_container<T,CA,VPC>& r );
151 template< class Iterator >
152 bool is_null( Iterator i );
155 template<class Archive, class T, class CA, class VPC>
156 void serialize( Archive& ar, reversible_ptr_container<T,CÁ,VPC>& c, const unsigned int version );
159 } // namespace 'boost'
171 Notice how these two types differ:
174 - ``typedef T* value_type;``
176 - notice this has pointer type
178 - ``typedef T& reference;``
180 - notice this is not a pointer type
182 This is done to be able to add pointers directly
183 to the container, but to hide the pointers externally.
186 - ``typedef *implementation defined* object_type;``
187 - this is ``T`` for sequences and sets
188 - this is ``std::pair<const Key, void*>`` for maps
192 - ``typedef ... iterator``
194 allows one to iterate over ``T&`` objects, not ``T*``.
200 returns an iterator that allows one to iterate over ``void*``
201 elements (*this is very rarely needed and you should not use the
202 functionality unless you know what you are doing*).
204 - ``typedef ... auto_type``
206 This declaration hides a pointer pointer type. You can rely on the following
211 T* operator->() const;
212 T& operator*() const;
215 operator *implementation-defined bool*\ ();
217 The destructor will delete the stored object *using the clone allocator of the container*
218 (this explains why we cannot use ``std::auto_ptr<T>``). It might help to
219 think it is just an ``std::auto_ptr<T>``. You can also return
220 the pointer from a function or assign it to another pointer via the ``move()``
226 auto_type other = boost::ptr_container::move( ptr );
227 return boost::ptr_container::move( other );
229 .. _construct/copy/destroy:
231 Semantics: construct/copy/destroy
232 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234 - ``reversible_ptr_container();``
236 - Effects: Constructs an empty container
238 - Postconditions: ``size() == 0``
241 - ``reversible_ptr_container( size_type n, const T& x );``
243 - Effects: Constructs a container with ``n`` clones of ``x``
245 - Postconditions: ``size() == n``
247 - ``explicit reversible_ptr_container( const reversible_ptr_container& r );``
249 - Effects: Constructs a container by cloning all elements of ``r``
251 - ``template< class Derived > explicit reversible_ptr_container( const reversible_ptr_container<Derived>& r );``
253 - Effects: Constructs a container by cloning all elements of ``r``
255 - Requirements: ``Derived`` is derived from ``T``
257 - ``explicit reversible_ptr_container( std::auto_ptr< reversible_ptr_container > r );``
259 - Effects: Constructs a container by taking ownership of the supplied pointers
262 - ``template< class InputIterator >``
263 ``reversible_ptr_container( InputIterator first, InputIterator last );``
265 - Requirements: ``(first,last]`` is a valid range
267 - Effects: Constructs a container with a cloned range of ``(first,last]``
269 - Postconditions: ``size() == std::distance( first, last )``
271 - ``~reversible_ptr_container();``
273 - Effects: Deletes the stored objects via the clone allocator
277 - ``reversible_ptr_container& operator=( const reversible_ptr_container& r );``
279 - Effects: Assigns a clone of ``r``
281 - Exception safety: strong guarantee
283 - ``template<class Derived> reversible_ptr_container& operator=( const reversible_ptr_container<Derived>& r );``
285 - Effects: Assigns a clone of ``r``
287 - Requirements: ``Derived`` is derived from ``T``
289 - Exception safety: Strong guarantee
291 - ``reversible_ptr_container& operator=( std::auto_ptr<reversible_ptr_container> r );``
293 - Effects: Deletes the stored objects and then takes ownership of the supplied pointers
297 - ``allocator_type get_allocator() const;``
299 - Effects: Returns a copy of the allocator of the container object
307 **See also:** `iterator invalidation <conventions.html#iterators-are-invalidated-as-in-the-corresponding-standard-container>`_
309 - ``iterator begin();``
310 - ``const_iterator begin() const;``
312 - Effects: Returns a mutable/non-mutable iterator with ``value_type T``
316 - ``iterator end();``
317 - ``const_iterator end() const;``
319 - Effects: Returns a mutable/non-mutable iterator with ``value_type T``
323 - ``reverse_iterator rbegin();``
325 - ``const_reverse_iterator rbegin() const;``
327 - Effects: Returns a mutable/non-mutable reverse iterator with ``value_type T``
331 - ``reverse_iterator rend();``
333 - ``const_reverse_iterator rend() const;``
335 - Effects: Returns a mutable/non-mutable reverse iterator with ``value_type T``
344 - ``size_type size() const;``
346 - Effects: Returns the number of stored elements
350 - ``size_type max_size() const;``
352 - Effects: Returns the maximum number of stored elements
356 - ``bool empty() const;``
358 - Effects: Returns whether the container is empty or not
368 - ``void swap( reversible_ptr_container& r );``
370 - Effects: Swaps the content of the two containers
376 - Effects: Destroys all object of the container
378 - Postconditions: ``empty() == true``
382 - ``VoidPtrContainer& base();``
384 - ``const VoidPtrContainer& base() const;``
386 - Returns: a reference to the wrapped container
388 .. _`pointer container requirements`:
390 Semantics: pointer container requirements
391 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
393 - ``auto_type replace( iterator position, T* x );``
395 - Requirements: ``not empty() and x != 0``
397 - Effects: returns the object pointed to by ``position`` and replaces it with ``x``.
399 - Throws: ``bad_ptr_container_operation`` if the container is empty and ``bad_pointer`` if ``x == 0``.
401 - Exception safety: Strong guarantee
403 - ``template< class U > auto_type replace( iterator position, std::auto_ptr<U> x );``
405 - Effects: ``return replace( position, x.release() );``
407 - ``std::auto_ptr< reversible_ptr_container > clone() const;``
409 - Effects: Returns a deep copy of the container
411 - Throws: ``std::bad_alloc`` if there is not enough memory to make a clone of the container
415 - ``std::auto_ptr< reversible_ptr_container > release();``
417 - Effects: Releases ownership of the container. This is a useful way of returning a container from a function.
419 - Postconditions: ``empty() == true``
421 - Throws: ``std::bad_alloc`` if the return value cannot be allocated
423 - Exception safety: Strong guarantee
425 - ``auto_type release( iterator position );``
427 - Requirements: ``not empty();``
429 - Effects: Releases ownership of the pointer referred to by position
431 - Postconditions: ``size()`` is one less
433 - Throws: ``bad_ptr_container_operation`` if the container is empty
435 - Exception safety: Strong guarantee
440 Semantics: comparison
441 ^^^^^^^^^^^^^^^^^^^^^
443 These functions compare the underlying range of objects.
446 operation( const ptr_container& l, const ptr_container& r );
448 has the effect one would expect of normal standard containers. Hence
449 objects are compared and not the pointers to objects.
453 Semantics: cloneability
454 ^^^^^^^^^^^^^^^^^^^^^^^
456 - ``template< class T, class CloneAllocator >
457 reversible_ptr_container<T,CA,VPC>*
458 new_clone( const reversible_ptr_container<T,CA,VPC>& r );``
461 - Effects: ``return r.clone().release();``
463 - Remarks: This function is only defined for concrete `pointer containers`_, but not for
464 `pointer container adapters`_.
466 .. _`pointer containers`: ptr_container.html#smart-containers
467 .. _`pointer container adapters`: ptr_container.html#smart-container-adapters
469 .. _`null predicate`:
471 Semantics: null predicate
472 ^^^^^^^^^^^^^^^^^^^^^^^^^
474 - ``template< class Iterator > bool is_null( Iterator i );``
476 - Requirements: ``i`` is a valid dereferencable iterator
478 - Returns: ``*i.base() == 0;``
482 Semantics: serialization
483 ^^^^^^^^^^^^^^^^^^^^^^^^
485 All containers can be serialized by means of
486 `Boost.Serialization`__. For an overview, see
487 `Serialization of Pointer Containers`_.
489 .. __: ../../serialization/index.html
490 .. _`Serialization of Pointer Containers`: reference.html#serialization
494 template<class Archive, class T, class CA, class VPC>
495 void serialize( Archive& ar, reversible_ptr_container<T,CA,VPC>& c, const unsigned int version );
498 - Effects: Saves or loads the container to/from the archive.
500 - Remarks: This function is called automatically be stream operators in
503 - Exception safety: Loading gives the basic guarantee
510 :Copyright: Thorsten Ottosen 2004-2007. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
512 __ http://www.boost.org/LICENSE_1_0.txt