ptr_sequence_adapter.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. ++++++++++++++++++++++++++++++++++
  2. |Boost| Pointer Container Library
  3. ++++++++++++++++++++++++++++++++++
  4. .. |Boost| image:: boost.png
  5. Class ``ptr_sequence_adapter``
  6. ------------------------------
  7. This section describes all the common operations for all the pointer
  8. sequences:
  9. - `ptr_vector <ptr_vector.html>`_
  10. - `ptr_list <ptr_list.html>`_
  11. - `ptr_deque <ptr_deque.html>`_
  12. The ``ptr_sequence_adapter`` is also a concrete class that you can use to create custom pointer
  13. containers from.
  14. **Hierarchy:**
  15. - `reversible_ptr_container <reversible_ptr_container.html>`_
  16. - ``ptr_sequence_adapter``
  17. - `ptr_vector <ptr_vector.html>`_
  18. - `ptr_list <ptr_list.html>`_
  19. - `ptr_deque <ptr_deque.html>`_
  20. - `ptr_array <ptr_array.html>`_
  21. **Navigate:**
  22. - `home <ptr_container.html>`_
  23. - `reference <reference.html>`_
  24. **Synopsis:**
  25. .. parsed-literal::
  26. namespace boost
  27. {
  28. template
  29. <
  30. class T,
  31. class VoidPtrSeq,
  32. class CloneAllocator = heap_clone_allocator
  33. >
  34. class ptr_sequence_adapter
  35. {
  36. public: // `construct/copy/destroy`_
  37. template< class InputIterator >
  38. assign( InputIterator first, InputIterator last );
  39. template< class InputRange >
  40. assign( const InputRange& e );
  41. public: // `element access`_
  42. T& front();
  43. const T& front() const;
  44. T& back();
  45. const T& back() const;
  46. public: // `modifiers`_
  47. void push_back( T* x );
  48. template< class U >
  49. void push_back( compatible-smart-ptr<U> x );
  50. auto_type pop_back();
  51. iterator insert( iterator position, T* x );
  52. template< class U >
  53. iterator insert( iterator position, compatible-smart-ptr<U> x );
  54. template< class InputIterator >
  55. void insert( iterator position, InputIterator first, InputIterator last );
  56. template< class InputRange >
  57. void insert( iterator position, const InputRange& r );
  58. iterator erase( iterator position );
  59. iterator erase( iterator first, iterator last );
  60. template< class Range >
  61. iterator erase( const Range& r );
  62. void resize( size_type size );
  63. void resize( size_type size, T* to_clone );
  64. public: // `pointer container requirements`_
  65. template< class PtrSequence >
  66. void transfer( iterator before, typename PtrSequence::iterator object,
  67. PtrSequence& from );
  68. template< class PtrSequence >
  69. void transfer( iterator before, typename PtrSequence::iterator first, typename PtrSequence::iterator last,
  70. PtrSequence& from );
  71. void template< class PtrSequence, class Range >
  72. void transfer( iterator before, const Range& r, PtrSequence& from );
  73. template< class PtrSequence >
  74. void transfer( iterator before, PtrSequence& from );
  75. public: // `algorithms`_
  76. void sort();
  77. void sort( iterator first, iterator last );
  78. template< class Compare >
  79. void sort( Compare comp );
  80. template< class Compare >
  81. void sort( iterator begin, iterator end, Compare comp );
  82. void unique();
  83. void unique( iterator first, iterator last );
  84. template< class Compare >
  85. void unique( Compare comp );
  86. template< class Compare >
  87. void unique( iterator begin, iterator end, Compare comp );
  88. template< class Pred >
  89. void erase_if( Pred pred );
  90. template< class Pred >
  91. void erase_if( iterator begin, iterator end, Pred pred );
  92. void merge( ptr_sequence_adapter& r );
  93. template< class Compare >
  94. void merge( ptr_sequence_adapter& r, Compare comp );
  95. void merge( iterator first, iterator last, ptr_sequence_adapter& from );
  96. template< class Compare >
  97. void merge( iterator first, iterator last, ptr_sequence_adapter& from, Compare comp );
  98. public: // `ptr_list interface`_
  99. public: // `ptr_vector interface`_
  100. public: // `ptr_deque interface`_
  101. }; // class 'ptr_sequence_adapter'
  102. } // namespace 'boost'
  103. .. _`ptr_list interface`: ptr_list.html
  104. .. _`ptr_vector interface`: ptr_vector.html
  105. .. _`ptr_deque interface`: ptr_deque.html
  106. Semantics
  107. ---------
  108. .. _`construct/copy/destroy`:
  109. Semantics: construct/copy/destroy
  110. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  111. - ``template< class InputIterator >
  112. void assign( InputIterator first, InputIterator last );``
  113. - Requirements: ``(first,last]`` is a valid range
  114. - Effects: ``clear(); insert( first, last );``
  115. - Postconditions: ``size() == std::distance( first, last );``
  116. - Exception safety: strong guarantee
  117. - ``template< class InputRange >
  118. void assign( const InputRange& r );``
  119. - Effects: ``assign( boost::begin(r), boost::end(r) );``
  120. ..
  121. - ``assign( size_type n, const T& u )``
  122. - Effects: ``clear(); insert( begin(), n, u );``
  123. - Postconditions: ``size() == n``
  124. - Exception safety: Strong guarantee
  125. ..
  126. void resize( size_type sz, const T& x );
  127. Effects:
  128. if ( sz > size() )
  129. insert( end(), sz-size(), x );
  130. else if ( sz < size() )
  131. erase( begin()+sz, end() );
  132. else
  133. ; //do nothing
  134. Postconditions: size() == sz
  135. Exception safety: Strong guarantee
  136. .. _`element access`:
  137. Semantics: element access
  138. ^^^^^^^^^^^^^^^^^^^^^^^^^
  139. - ``T& front();``
  140. - Requirements: ``not empty();``
  141. - Effects: ``return *begin();``
  142. - ``const T& front() const;``
  143. - Requirements: ``not empty();``
  144. - Effects: ``return *begin();``
  145. - ``T& back();``
  146. - Requirements: ``not empty();``
  147. - Effects: ``return *--end();``
  148. - ``const T& back() const;``
  149. - Requirements: ``not empty();``
  150. - Effects: ``return *--end();``
  151. .. _`modifiers`:
  152. Semantics: modifiers
  153. ^^^^^^^^^^^^^^^^^^^^
  154. - ``void push_back( T* x );``
  155. - Requirements: ``x != 0``
  156. - Effects: Inserts the pointer into container and takes ownership of it
  157. - Throws: ``bad_pointer`` if ``x == 0``
  158. - Exception safety: Strong guarantee
  159. - ``template< class U > void push_back( compatible-smart-ptr<U> x );``
  160. - Effects: ``push_back( x.release() );``
  161. ..
  162. - ``void push_back( const T& x );``
  163. - Effects: ``push_back( CloneAllocator::clone( x ) );``
  164. - Exception safety: Strong guarantee
  165. - ``auto_type pop_back();``
  166. - Requirements:``not empty()``
  167. - Effects: Removes the last element in the container
  168. - Postconditions: ``size()`` is one less
  169. - Throws: ``bad_ptr_container_operation`` if ``empty() == true``
  170. - Exception safety: Strong guarantee
  171. - ``iterator insert( iterator position, T* x );``
  172. - Requirements: ``position`` is a valid iterator from the container and
  173. ``x != 0``
  174. - Effects: Inserts ``x`` before ``position`` and returns an iterator pointing to it
  175. - Throws: ``bad_pointer`` if ``x == 0``
  176. - Exception safety: Strong guarantee
  177. - ``template< class U > iterator insert( iterator position, compatible-smart-ptr<U> x );``
  178. - Effects: ``return insert( position, x.release() );``
  179. ..
  180. - ``iterator insert( iterator position, const T& x );``
  181. - Requirements: ``position`` is a valid iterator from the container
  182. - Effects: ``return insert( position, CloneAllocator::clone( x ) );``
  183. - Exception safety: Strong guarantee
  184. - ``void insert( iterator position, size_type n, const T& x );``
  185. - Requirements: ``position`` is a valid iterator from the container
  186. - Effects: Inserts ``n`` clones of ``x`` before position into the container
  187. - Exception safety: Strong guarantee
  188. - ``template< class InputIterator >
  189. void insert( iterator position, InputIterator first, InputIterator last );``
  190. - Requirements: ``position`` is a valid iterator from the container
  191. - Effects: Inserts a cloned range before ``position``
  192. - Exception safety: Strong guarantee
  193. - ``template< class InputRange >
  194. void insert( iterator position, const InputRange& r );``
  195. - Effects: ``insert( position, boost::begin(r), boost::end(r) );``
  196. - ``iterator erase( iterator position );``
  197. - Requirements: ``position`` is a valid iterator from the container
  198. - Effects: Removes the element defined by ``position`` and returns an iterator to the following element
  199. - Throws: Nothing
  200. - ``iterator erase( iterator first, iterator last );``
  201. - Requirements: ``[first,last)`` is a valid range
  202. - Effects: Removes the range of element defined by ``[first,last)`` and returns an iterator to the following element
  203. - Throws: Nothing
  204. - ``template< class Range >
  205. void erase( const Range& r );``
  206. - Effects: ``erase( boost::begin(r), boost::end(r) );``
  207. - ``void resize( size_type size );``
  208. - Effects: Resizes the container. If elements are erased, it happens from the back. If elements are inserted, it happens at the back.
  209. - Requirements: ``T`` is default constructible
  210. - Postcondition: ``size() == size;``
  211. - Exception safety: Basic guarantee under expansion; nothrow guarantee otherwise
  212. - ``void resize( size_type size, T* to_clone );``
  213. - Effects: Resizes the container. If elements are erased, it happens from the back. If elements are inserted, clones of ``*to_clone`` are inserted at the back.
  214. - Postcondition: ``size() == size;``
  215. - Exception safety: Basic guarantee under expansion; nothrow guarantee otherwise
  216. - Remarks: ``to_clone == 0`` is valid if the container supports nulls. The container does not take ownership of ``to_clone``.
  217. .. _`pointer container requirements`:
  218. Semantics: pointer container requirements
  219. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  220. You can use ``transfer()`` to move elements between two containers of the same type. Furthermore,
  221. you can also move elements from a container of type ``T`` to a container of type ``U`` as long as
  222. ``T::value_type`` is convertible to ``U::value_type``. An example would be transferring from ``boost::ptr_vector<Derived>``
  223. to ``boost::ptr_deque<Base>``.
  224. (**Remark:** *When moving elements between two different containers, it is your responsibility to make sure the allocators are compatible.*
  225. *The special latitude of being able to transfer between two different containers is only available for Sequences and not for Associative Containers.*)
  226. ..
  227. - ``template< class PtrSequence > void transfer( iterator before, typename PtrSequence::iterator object, PtrSequence& from );``
  228. - Effects: Inserts the object defined by ``object`` into the container and remove it from ``from``.
  229. Insertion takes place before ``before``.
  230. - Postconditions: If ``from.empty()``, nothing happens. Otherwise
  231. ``size()`` is one more, ``from.size()`` is one less.
  232. - Exception safety: Strong guarantee
  233. - ``template< class PtrSequence > void transfer( iterator before, typename PtrSequence::iterator first, typename PtrSequence::iterator last, PtrSequence& from );``
  234. - Requirements: ``from.size() >= std::distance(first,last)``
  235. - Effects: Inserts the objects defined by the range ``[first,last)`` into the container and remove it from ``from``.
  236. Insertion takes place before ``before``.
  237. - Postconditions: If ``from.empty()``, nothing happens. Otherwise,
  238. let ``N == std::distance(first,last);`` then ``size()`` is ``N`` more, ``from.size()`` is ``N`` less.
  239. - Exception safety: Strong guarantee
  240. - Complexity: Linear or better
  241. - ``void template< class PtrSequence, class Range > void transfer( iterator before, const Range& r, PtrSequence& from );``
  242. - Effects: ``transfer(before, boost::begin(r), boost::end(r), from);``
  243. - ``template< class PtrSequence> void transfer( iterator before, PtrSequence& from );``
  244. - Effects: ``transfer(before, from, from);``
  245. .. _`algorithms`:
  246. Semantics: algorithms
  247. ^^^^^^^^^^^^^^^^^^^^^
  248. The general requirement for these algorithms is that the container *does not
  249. contain any nulls*.
  250. - ``void sort();``
  251. - ``void sort( iterator first, iterator last );``
  252. - ``template< class Compare > void sort( Compare comp );``
  253. - ``template< class Compare > void sort( iterator begin, iterator end, Compare comp );``
  254. - Requirements: (versions without ``Compare``) ``bool operator<( const T&, const T& )`` is defined
  255. - Requirements: (``Compare`` versions) ``Compare`` must take ``const T&`` arguments
  256. - Effects: sorts the entire container or the specified range
  257. - Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
  258. - Remarks: The versions of ``sort()`` that take two iterators are not available for ``ptr_list``
  259. - ``void unique();``
  260. - ``void unique( iterator first, iterator last );``
  261. - ``template< class Compare > void unique( Compare comp );``
  262. - ``template< class Compare > void unique( iterator begin, iterator end, Compare comp );``
  263. - Requirements: (versions without ``Compare``) ``bool operator==( const T&, const T& )`` is defined
  264. - Requirements: (``Compare`` versions) ``Compare`` must take ``const T&`` arguments
  265. - Effects: removes adjacent and equal objects from the entire container or the specified range
  266. - Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
  267. - ``template< class Pred > void erase_if( Pred pred );``
  268. - ``template< class Pred > void erase_if( iterator begin, iterator end, Pred pred );``
  269. - Requirements: ``Pred`` must take an ``const T&`` argument
  270. - Effects: removes all elements ``t`` for which ``pred(t)`` returns ``true`` from the entire container or the specified range
  271. - Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
  272. - ``void merge( ptr_sequence_adapter& r );``
  273. - ``template< class Compare > void merge( ptr_sequence_adapter& r, Compare comp );``
  274. - ``void merge( iterator first, iterator last, ptr_sequence_adapter& from );``
  275. - ``template< class Compare > void merge( iterator first, iterator last, ptr_sequence_adapter& from, Compare comp );``
  276. - Requirements: (``Compare`` versions) ``Compare`` must take ``const T&`` arguments
  277. - Requirements: both sequences are sorted wrt. the same predicate
  278. - Effects: transfers the entire container or the specified sequence to the container while
  279. ensuring the new sequence is also sorted
  280. - Postconditions: (Container versions) ``r.empty()``
  281. - Exception safety: nothrow guarantee (the behavior is undefined if the comparison operator throws)
  282. .. raw:: html
  283. <hr>
  284. :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
  285. __ http://www.boost.org/LICENSE_1_0.txt