ptr_vector.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. ++++++++++++++++++++++++++++++++++
  2. |Boost| Pointer Container Library
  3. ++++++++++++++++++++++++++++++++++
  4. .. |Boost| image:: boost.png
  5. Class ``ptr_vector``
  6. --------------------
  7. A ``ptr_vector<T>`` is a pointer container that uses an underlying ``std::vector<void*>``
  8. to store the pointers.
  9. **Hierarchy:**
  10. - `reversible_ptr_container <reversible_ptr_container.html>`_
  11. - `ptr_sequence_adapter <ptr_sequence_adapter.html>`_
  12. - ``ptr_vector``
  13. - `ptr_list <ptr_list.html>`_
  14. - `ptr_deque <ptr_deque.html>`_
  15. - `ptr_array <ptr_array.html>`_
  16. **Navigate:**
  17. - `home <ptr_container.html>`_
  18. - `reference <reference.html>`_
  19. **Synopsis:**
  20. .. parsed-literal::
  21. namespace boost
  22. {
  23. template
  24. <
  25. class T,
  26. class CloneAllocator = heap_clone_allocator,
  27. class Allocator = std::allocator<void*>
  28. >
  29. class ptr_vector : public ptr_sequence_adapter
  30. <
  31. T,
  32. std::vector<void*,Allocator>,
  33. CloneAllocator
  34. >
  35. {
  36. public: // `construction`_
  37. explicit ptr_vector( size_type to_reserve );
  38. public: // capacity_
  39. size_type capacity() const;
  40. void reserve( size_type n );
  41. public: // `element access`_
  42. T& operator[]( size_type n );
  43. const T& operator[]( size_type n ) const;
  44. T& at( size_type n );
  45. const T& at( size_type n ) const;
  46. public: // `pointer container requirements`_
  47. auto_type replace( size_type idx, T* x );
  48. template< class U >
  49. auto_type replace( size_type idx, compatible-smart-ptr<U> x );
  50. bool is_null( size_type idx ) const;
  51. public: // `C-array support`_
  52. void transfer( iterator before, T** from, size_type size, bool delete_from = true );
  53. T** c_array();
  54. };
  55. } // namespace 'boost'
  56. Semantics
  57. ---------
  58. .. _`construction`:
  59. Semantics: construction
  60. ^^^^^^^^^^^^^^^^^^^^^^^
  61. - ``explicit ptr_vector( size_type to_reserve );``
  62. - constructs an empty vector with a buffer
  63. of size least ``to_reserve``
  64. .. _`capacity`:
  65. Semantics: capacity
  66. ^^^^^^^^^^^^^^^^^^^
  67. - ``size_type capacity() const;``
  68. - Effects: Returns the size of the allocated buffer
  69. - Throws: Nothing
  70. - ``void reserve( size_type n );``
  71. - Requirements: ``n <= max_size()``
  72. - Effects: Expands the allocated buffer
  73. - Postcondition: ``capacity() >= n``
  74. - Throws: ``std::length_error()`` if ``n > max_size()``
  75. .. _`element access`:
  76. Semantics: element access
  77. ^^^^^^^^^^^^^^^^^^^^^^^^^
  78. - ``T& operator[]( size_type n );``
  79. - ``const T& operator[]( size_type n ) const;``
  80. - Requirements: ``n < size()``
  81. - Effects: Returns a reference to the ``n``'th element
  82. - Throws: Nothing
  83. - ``T& at( size_type n );``
  84. - ``const T& at( size_type n ) const;``
  85. - Requirements: ``n < size()``
  86. - Effects: Returns a reference to the ``n``'th element
  87. - Throws: ``bad_index`` if ``n >= size()``
  88. .. _`pointer container requirements`:
  89. Semantics: pointer container requirements
  90. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  91. - ``auto_type replace( size_type idx, T* x );``
  92. - Requirements: `` x != 0 and idx < size()``
  93. - Effects: returns the object indexed by ``idx`` and replaces it with ``x``.
  94. - Throws: ``bad_index`` if ``idx >= size()`` and ``bad_pointer`` if ``x == 0``.
  95. - Exception safety: Strong guarantee
  96. - ``template< class U > auto_type replace( size_type idx, compatible-smart-ptr<U> x );``
  97. - Effects: ``return replace( idx, x.release() );``
  98. - ``bool is_null( size_type idx ) const;``
  99. - Requirements: ``idx < size()``
  100. - Effects: returns whether the pointer at index ``idx`` is null
  101. - Exception safety: Nothrow guarantee
  102. .. _`C-array support`:
  103. Semantics: C-array support
  104. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  105. - ``void transfer( iterator before, T** from, size_type size, bool delete_from = true );``
  106. - Requirements: ``from != 0``
  107. - Effects: Takes ownership of the dynamic array ``from``
  108. - Exception safety: Strong guarantee if ``delete_from == true``; if ``delete_from == false``,
  109. and an exception is thrown, the container fails to take ownership.
  110. - Remarks: Eventually calls ``delete[] from`` if ``delete_from == true``.
  111. - ``T** c_array();``
  112. - Returns: ``0`` if the container is empty; otherwise a pointer to the first element of the stored array
  113. - Throws: Nothing
  114. .. raw:: html
  115. <hr>
  116. :Copyright: Thorsten Ottosen 2004-2007. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
  117. __ http://www.boost.org/LICENSE_1_0.txt