ptr_array.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. ++++++++++++++++++++++++++++++++++
  2. |Boost| Pointer Container Library
  3. ++++++++++++++++++++++++++++++++++
  4. .. |Boost| image:: boost.png
  5. Class ``ptr_array``
  6. -------------------
  7. A ``ptr_array<T,size>`` is a pointer container that uses an underlying ``boost::array<void*,size>``
  8. to store the pointers. The class is useful when there is no requirement
  9. of dynamic expansion and when no overhead is tolerable.
  10. **Hierarchy:**
  11. - `reversible_ptr_container <reversible_ptr_container.html>`_
  12. - `ptr_sequence_adapter <ptr_sequence_adapter.html>`_
  13. - `ptr_vector <ptr_vector.html>`_
  14. - `ptr_list <ptr_list.html>`_
  15. - `ptr_deque <ptr_deque.html>`_
  16. - ``ptr_array``
  17. **Navigate:**
  18. - `home <ptr_container.html>`_
  19. - `reference <reference.html>`_
  20. **Synopsis:**
  21. .. parsed-literal::
  22. namespace boost
  23. {
  24. template
  25. <
  26. class T,
  27. size_t N,
  28. CloneAllocator = heap_clone_allocator
  29. >
  30. class ptr_array : public *implementation-defined*
  31. {
  32. public: // `construct/copy/destroy`_
  33. ptr_array();
  34. explicit ptr_array( const ptr_array& r );
  35. template< class U >
  36. explicit ptr_array( const ptr_array<U,N>& r );
  37. explicit ptr_array( compatible-smart-ptr<ptr_array>& r );
  38. ptr_array& operator=( const ptr_array& r );
  39. template< class U >
  40. ptr_array& operator=( const ptr_array<U,N>& r );
  41. ptr_array& operator=( compatible-smart-ptr<this_type> r );
  42. public: // `iterators`_
  43. public: // `capacity`_
  44. public: // `element access`_
  45. T& front();
  46. const T& front() const;
  47. T& back();
  48. const T& back() const;
  49. template< size_t idx >
  50. T& at();
  51. template< size_t idx >
  52. const T& at() const;
  53. T& at( size_t );
  54. const T& at( size_t );
  55. T& operator[]( size_t );
  56. const T& operator[]( size_t ) const;
  57. public: // `modifiers`_
  58. void swap( ptr_array& r );
  59. template< size_t idx >
  60. auto_type replace( T* r );
  61. template< size_t idx, class U >
  62. auto_type replace( compatible-smart-ptr<U> r );
  63. auto_type replace( size_t idx, T* r );
  64. template< class U >
  65. auto_type replace( size_t idx, compatible-smart-ptr<U> r );
  66. public: // `pointer container requirements`_
  67. compatible-smart-ptr<ptr_array> clone() const;
  68. compatible-smart-ptr<ptr_array> release();
  69. template< size_t idx >
  70. bool is_null() const;
  71. bool is_null( size_t idx ) const;
  72. }; // class 'ptr_sequence_adapter'
  73. } // namespace 'boost'
  74. .. _iterators: reversible_ptr_container.html#iterators
  75. .. _capacity: reversible_ptr_container.html#capacity
  76. .. _`inherited element access`: reversible_ptr_container.html#element-access
  77. Semantics
  78. ---------
  79. .. _`construct/copy/destroy`:
  80. Semantics: construct/copy/destroy
  81. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  82. - ``ptr_array();``
  83. - Effects: constructs array where each element is null
  84. - ``explicit ptr_array( const ptr_array& r );``
  85. - ``template< class U >
  86. explicit ptr_array( const ptr_array<U,N>& r );``
  87. - Effects: Constructs array by cloning ``r``
  88. - ``ptr_array( compatible-smart-ptr<ptr_array>& r );``
  89. - Effects: take ownership of the supplied pointers
  90. - ``ptr_array& operator=( const ptr_array& r );``
  91. - ``template< class U > ptr_array& operator=( const ptr_array<U,N>& r );``
  92. - Effects: Assigns a clone of ``r``
  93. - Exception safety: Strong guarantee
  94. - ``ptr_array& operator=( compatible-smart-ptr<this_type> r );``
  95. - Effects: take ownership of the supplied pointers
  96. - Throws: Nothing
  97. .. _`element access`:
  98. Semantics: element access
  99. ^^^^^^^^^^^^^^^^^^^^^^^^^
  100. - ``T& front();``
  101. - ``const T& front() const;``
  102. - Requirements: ``not empty();``
  103. - Effects: ``return *begin();``
  104. - Throws: ``bad_ptr_container_operation`` if ``empty() == true``
  105. - ``T& back();``
  106. - ``const T& back() const;``
  107. - Requirements: ``not empty();``
  108. - Effects: ``return *--end();``
  109. - Throws: ``bad_ptr_container_operation`` if ``empty() == true``
  110. - ``template< size_t idx > T& at( size_type n );``
  111. - ``template< size_t idx > const T& at( size_type n ) const;``
  112. - Requirements: ``idx < size()`` (compile-time enforced)
  113. - Effects: Returns a reference to the ``n``'th element
  114. - Throws: nothing
  115. - ``T& at( size_type n );``
  116. - ``const T& at( size_type n ) const;``
  117. - Requirements: ``n < size()``
  118. - Effects: Returns a reference to the ``n``'th element
  119. - Throws: ``bad_index`` if ``n >=size()``
  120. - ``T& operator[]( size_type n );``
  121. - ``const T& operator[]( size_type n ) const;``
  122. - Requirements: ``n < size()``
  123. - Effects: Returns a reference to the ``n``'th element
  124. - Throws: Nothing
  125. .. _`modifiers`:
  126. Semantics: modifiers
  127. ^^^^^^^^^^^^^^^^^^^^
  128. - ``void swap( ptr_array& r );``
  129. - Effects: swaps the two arrays
  130. - Complexity: Linear
  131. - Throws: nothing
  132. - ``template< size_t idx > auto_type replace( T* r );``
  133. - Requirements:
  134. - ``idx < size()`` (compile-time enforced)
  135. - ``r != 0``
  136. - Effects: returns the object indexed by ``idx`` and replaces it with ``r``.
  137. - Throws: ``bad_pointer`` if ``x == 0``.
  138. - Exception safety: Strong guarantee
  139. - ``template< size_t idx, class U > auto_type replace( compatible-smart-ptr<U> r );``
  140. - Effects: ``return replace<idx>( r.release() );``
  141. - ``auto_type replace( size_t idx, T* r );``
  142. - Requirements: `` x != 0 and idx < size()``
  143. - Effects: returns the object indexed by ``idx`` and replaces it with ``x``.
  144. - Throws: ``bad_index`` if ``idx >= size()`` and ``bad_pointer`` if ``x == 0``.
  145. - Exception safety: Strong guarantee
  146. - ``template< class U > auto_type replace( size_t idx, compatible-smart-ptr<U> r );``
  147. - Effects: ``return replace( idx, r.release() );``
  148. .. _`pointer container requirements`:
  149. Semantics: pointer container requirements
  150. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  151. - ``compatible-smart-ptr<ptr_array> clone() const;``
  152. - Effects: Returns a deep copy of the container
  153. - Throws: ``std::bad_alloc`` if there is not enough memory to make a clone of the container
  154. - Complexity: Linear
  155. - ``compatible-smart-ptr<ptr_array> release();``
  156. - Effects: Releases ownership of the container. This is a useful way of returning a container from a function.
  157. - Postconditions: ``empty() == true`` and all pointers are null
  158. - Throws: ``std::bad_alloc`` if the return value cannot be allocated
  159. - Exception safety: Strong guarantee
  160. - ``template< size_t idx > bool is_null() const;``
  161. - Requirements: ``idx < size()`` (compile-time enforced)
  162. - Effects: returns whether the pointer at index ``idx`` is null
  163. - Exception safety: Nothrow guarantee
  164. - ``bool is_null( size_type idx ) const;``
  165. - Requirements: ``idx < size()``
  166. - Effects: returns whether the pointer at index ``idx`` is null
  167. - Exception safety: Nothrow guarantee
  168. .. raw:: html
  169. <hr>
  170. :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
  171. __ http://www.boost.org/LICENSE_1_0.txt