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
|
++++++++++++++++++++++++++++++++++
|Boost| Pointer Container Library
++++++++++++++++++++++++++++++++++
.. |Boost| image:: boost.png
Class ``ptr_sequence_adapter``
------------------------------
This section describes all the common operations for all the pointer
sequences:
- `ptr_vector <ptr_vector.html>`_
- `ptr_list <ptr_list.html>`_
- `ptr_deque <ptr_deque.html>`_
The ``ptr_sequence_adapter`` is also a concrete class that you can use to create custom pointer
containers from.
**Hierarchy:**
- `reversible_ptr_container <reversible_ptr_container.html>`_
- ``ptr_sequence_adapter``
- `ptr_vector <ptr_vector.html>`_
- `ptr_list <ptr_list.html>`_
- `ptr_deque <ptr_deque.html>`_
- `ptr_array <ptr_array.html>`_
**Navigate:**
- `home <ptr_container.html>`_
- `reference <reference.html>`_
**Synopsis:**
.. parsed-literal::
namespace boost
{
template
<
class T,
class VoidPtrSeq,
class CloneAllocator = heap_clone_allocator
>
class ptr_sequence_adapter
{
public: // `construct/copy/destroy`_
template< class InputIterator >
assign( InputIterator first, InputIterator last );
template< class InputRange >
assign( const InputRange& e );
public: // `element access`_
T& front();
const T& front() const;
T& back();
const T& back() const;
public: // `modifiers`_
void push_back( T* x );
template< class U >
void push_back( std::auto_ptr<U> x );
auto_type pop_back();
iterator insert( iterator position, T* x );
template< class U >
iterator insert( iterator position, std::auto_ptr<U> x );
template< class InputIterator >
void insert( iterator position, InputIterator first, InputIterator last );
template< class InputRange >
void insert( iterator position, const InputRange& r );
iterator erase( iterator position );
iterator erase( iterator first, iterator last );
template< class Range >
iterator erase( const Range& r );
public: // `pointer container requirements`_
template< class PtrSequence >
void transfer( iterator before, typename PtrSequence::iterator object,
PtrSequence& from );
template< class PtrSequence >
void transfer( iterator before, typename PtrSequence::iterator first, typename PtrSequence::iterator last,
PtrSequence& from );
void template< class PtrSequence, class Range >
void transfer( iterator before, const Range& r, PtrSequence& from );
template< class PtrSequence >
void transfer( iterator before, PtrSequence& from );
public: // `algorithms`_
void sort();
void sort( iterator first, iterator last );
template< class Compare >
void sort( Compare comp );
template< class Compare >
void sort( iterator begin, iterator end, Compare comp );
void unique();
void unique( iterator first, iterator last );
template< class Compare >
void unique( Compare comp );
template< class Compare >
void unique( iterator begin, iterator end, Compare comp );
template< class Pred >
void erase_if( Pred pred );
template< class Pred >
void erase_if( iterator begin, iterator end, Pred pred );
void merge( ptr_sequence_adapter& r );
template< class Compare >
void merge( ptr_sequence_adapter& r, Compare comp );
void merge( iterator first, iterator last, ptr_sequence_adapter& from );
template< class Compare >
void merge( iterator first, iterator last, ptr_sequence_adapter& from, Compare comp );
public: // `ptr_list interface`_
public: // `ptr_vector interface`_
public: // `ptr_deque interface`_
}; // class 'ptr_sequence_adapter'
} // namespace 'boost'
.. _`ptr_list interface`: ptr_list.html
.. _`ptr_vector interface`: ptr_vector.html
.. _`ptr_deque interface`: ptr_deque.html
Semantics
---------
.. _`construct/copy/destroy`:
Semantics: construct/copy/destroy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- ``template< class InputIterator >
void assign( InputIterator first, InputIterator last );``
- Requirements: ``(first,last]`` is a valid range
- Effects: ``clear(); insert( first, last );``
- Postconditions: ``size() == std::distance( first, last );``
- Exception safety: strong guarantee
- ``template< class InputRange >
void assign( const InputRange& r );``
- Effects: ``assign( boost::begin(r), boost::end(r) );``
..
- ``assign( size_type n, const T& u )``
- Effects: ``clear(); insert( begin(), n, u );``
- Postconditions: ``size() == n``
- Exception safety: Strong guarantee
..
void resize( size_type sz, const T& x );
Effects:
if ( sz > size() )
insert( end(), sz-size(), x );
else if ( sz < size() )
erase( begin()+sz, end() );
else
; //do nothing
Postconditions: size() == sz
Exception safety: Strong guarantee
.. _`element access`:
Semantics: element access
^^^^^^^^^^^^^^^^^^^^^^^^^
- ``T& front();``
- Requirements: ``not empty();``
- Effects: ``return *begin();``
- Throws: ``bad_ptr_container_operation`` if ``empty() == true``
- ``const T& front() const;``
- Requirements: ``not empty();``
- Effects: ``return *begin();``
- Throws: ``bad_ptr_container_operation`` if ``empty() == true``
- ``T& back();``
- Requirements: ``not empty();``
- Effects: ``return *--end();``
- Throws: ``bad_ptr_container_operation`` if ``empty() == true``
- ``const T& back() const;``
- Requirements: ``not empty();``
- Effects: ``return *--end();``
- Throws: ``bad_ptr_container_operation`` if ``empty() == true``
.. _`modifiers`:
Semantics: modifiers
^^^^^^^^^^^^^^^^^^^^
- ``void push_back( T* x );``
- Requirements: ``x != 0``
- Effects: Inserts the pointer into container and takes ownership of it
- Throws: ``bad_pointer`` if ``x == 0``
- Exception safety: Strong guarantee
- ``template< class U > void push_back( std::auto_ptr<U> x );``
- Effects: ``push_back( x.release() );``
..
- ``void push_back( const T& x );``
- Effects: ``push_back( CloneAllocator::clone( x ) );``
- Exception safety: Strong guarantee
- ``auto_type pop_back();``
- Requirements:``not empty()``
- Effects: Removes the last element in the container
- Postconditions: ``size()`` is one less
- Throws: ``bad_ptr_container_operation`` if ``empty() == true``
- Exception safety: Strong guarantee
- ``iterator insert( iterator position, T* x );``
- Requirements: ``position`` is a valid iterator from the container and
``x != 0``
- Effects: Inserts ``x`` before ``position`` and returns an iterator pointing to it
- Throws: ``bad_pointer`` if ``x == 0``
- Exception safety: Strong guarantee
- ``template< class U > iterator insert( iterator position, std::auto_ptr<U> x );``
- Effects: ``return insert( position, x.release() );``
..
- ``iterator insert( iterator position, const T& x );``
- Requirements: ``position`` is a valid iterator from the container
- Effects: ``return insert( position, CloneAllocator::clone( x ) );``
- Exception safety: Strong guarantee
- ``void insert( iterator position, size_type n, const T& x );``
- Requirements: ``position`` is a valid iterator from the container
- Effects: Inserts ``n`` clones of ``x`` before position into the container
- Exception safety: Strong guarantee
- ``template< class InputIterator >
void insert( iterator position, InputIterator first, InputIterator last );``
- Requirements: ``position`` is a valid iterator from the container
- Effects: Inserts a cloned range before ``position``
- Exception safety: Strong guarantee
- ``template< class InputRange >
void insert( iterator position, const InputRange& r );``
- Effects: ``insert( position, boost::begin(r), boost::end(r) );``
- ``iterator erase( iterator position );``
- Requirements: ``position`` is a valid iterator from the container
- Effects: Removes the element defined by ``position`` and returns an iterator to the following element
- Throws: Nothing
- ``iterator erase( iterator first, iterator last );``
- Requirements: ``[first,last)`` is a valid range
- Effects: Removes the range of element defined by ``[first,last)`` and returns an iterator to the following element
- Throws: Nothing
- ``template< class Range >
void erase( const Range& r );``
- Effects: ``erase( boost::begin(r), boost::end(r) );``
.. _`pointer container requirements`:
Semantics: pointer container requirements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can use ``transfer()`` to move elements between two containers of the same type. Furthermore,
you can also move elements from a container of type ``T`` to a container of type ``U`` as long as
``T::value_type`` is convertible to ``U::value_type``. An example would be transferring from ``boost::ptr_vector<Derived>``
to ``boost::ptr_deque<Base>``.
(**Remark:** *When moving elements between two different containers, it is your responsibility to make sure the allocators are compatible.*
*The special latitude of being able to transfer between two different containers is only available for Sequences and not for Associative Containers.*)
..
- ``template< class PtrSequence > void transfer( iterator before, typename PtrSequence::iterator object, PtrSequence& from );``
- Effects: Inserts the object defined by ``object`` into the container and remove it from ``from``.
Insertion takes place before ``before``.
- Postconditions: If ``from.empty()``, nothing happens. Otherwise
``size()`` is one more, ``from.size()`` is one less.
- Exception safety: Strong guarantee
- ``template< class PtrSequence > void transfer( iterator before, typename PtrSequence::iterator first, typename PtrSequence::iterator last, PtrSequence& from );``
- Requirements: ``from.size() >= std::distance(first,last)``
- Effects: Inserts the objects defined by the range ``[first,last)`` into the container and remove it from ``from``.
Insertion takes place before ``before``.
- Postconditions: If ``from.empty()``, nothing happens. Otherwise,
let ``N == std::distance(first,last);`` then ``size()`` is ``N`` more, ``from.size()`` is ``N`` less.
- Exception safety: Strong guarantee
- Complexity: Linear or better
- ``void template< class PtrSequence, class Range > void transfer( iterator before, const Range& r, PtrSequence& from );``
- Effects: ``transfer(before, boost::begin(r), boost::end(r), from);``
- ``template< class PtrSequence> void transfer( iterator before, PtrSequence& from );``
- Effects: ``transfer(before, from, from);``
.. _`algorithms`:
Semantics: algorithms
^^^^^^^^^^^^^^^^^^^^^
The general requirement for these algorithms is that the container *does not
contain any nulls*.
- ``void sort();``
- ``void sort( iterator first, iterator last );``
- ``template< class Compare > void sort( Compare comp );``
- ``template< class Compare > void sort( iterator begin, iterator end, Compare comp );``
- Requirements: (versions without ``Compare``) ``bool operator<( const T&, const T& )`` is defined
- Requirements: (``Compare`` versions) ``Compare`` must take ``const T&`` arguments
- Effects: sorts the entire container or the specified range
- Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
- Remarks: The versions of ``sort()`` that take two iterators are not available for ``ptr_list``
- ``void unique();``
- ``void unique( iterator first, iterator last );``
- ``template< class Compare > void unique( Compare comp );``
- ``template< class Compare > void unique( iterator begin, iterator end, Compare comp );``
- Requirements: (versions without ``Compare``) ``bool operator==( const T&, const T& )`` is defined
- Requirements: (``Compare`` versions) ``Compare`` must take ``const T&`` arguments
- Effects: removes adjacent and equal objects from the entire container or the specified range
- Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
- ``template< class Pred > void erase_if( Pred pred );``
- ``template< class Pred > void erase_if( iterator begin, iterator end, Pred pred );``
- Requirements: ``Pred`` must take an ``const T&`` argument
- Effects: removes all elements ``t`` for which ``pred(t)`` returns ``true`` from the entire container or the specified range
- Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
- ``void merge( ptr_sequence_adapter& r );``
- ``template< class Compare > void merge( ptr_sequence_adapter& r, Compare comp );``
- ``void merge( iterator first, iterator last, ptr_sequence_adapter& from );``
- ``template< class Compare > void merge( iterator first, iterator last, ptr_sequence_adapter& from, Compare comp );``
- Requirements: (``Compare`` versions) ``Compare`` must take ``const T&`` arguments
- Requirements: both sequences are sorted wrt. the same predicate
- Effects: transfers the entire container or the specified sequence to the container while
ensuring the new sequence is also sorted
- Postconditions: (Container versions) ``r.empty()``
- Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
.. raw:: html
<hr>
:Copyright: Thorsten Ottosen 2004-2006. 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
|