1 // Boost.Container static_vector
3 // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
4 // Copyright (c) 2011-2013 Andrew Hundt.
5 // Copyright (c) 2013-2014 Ion Gaztanaga
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_CONTAINER_STATIC_VECTOR_HPP
12 #define BOOST_CONTAINER_STATIC_VECTOR_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 #include <boost/container/detail/type_traits.hpp>
25 #include <boost/container/vector.hpp>
28 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
29 #include <initializer_list>
32 namespace boost { namespace container {
34 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
38 template<class T, std::size_t N, std::size_t InplaceAlignment, bool ThrowOnOverflow>
39 class static_storage_allocator
41 typedef bool_<ThrowOnOverflow> throw_on_overflow_t;
43 static BOOST_NORETURN BOOST_CONTAINER_FORCEINLINE void on_capacity_overflow(true_type)
48 static BOOST_CONTAINER_FORCEINLINE void on_capacity_overflow(false_type)
50 BOOST_ASSERT_MSG(false, "ERROR: static vector capacity overflow");
56 BOOST_CONTAINER_FORCEINLINE static_storage_allocator() BOOST_NOEXCEPT_OR_NOTHROW
59 BOOST_CONTAINER_FORCEINLINE static_storage_allocator(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
62 BOOST_CONTAINER_FORCEINLINE static_storage_allocator & operator=(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
65 BOOST_CONTAINER_FORCEINLINE T* internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW
66 { return const_cast<T*>(static_cast<const T*>(static_cast<const void*>(storage.data))); }
68 BOOST_CONTAINER_FORCEINLINE T* internal_storage() BOOST_NOEXCEPT_OR_NOTHROW
69 { return static_cast<T*>(static_cast<void*>(storage.data)); }
71 static const std::size_t internal_capacity = N;
73 std::size_t max_size() const
76 static BOOST_CONTAINER_FORCEINLINE void on_capacity_overflow()
78 (on_capacity_overflow)(throw_on_overflow_t());
81 typedef boost::container::dtl::version_type<static_storage_allocator, 0> version;
83 BOOST_CONTAINER_FORCEINLINE friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
86 BOOST_CONTAINER_FORCEINLINE friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
90 BOOST_STATIC_ASSERT_MSG(!InplaceAlignment || (InplaceAlignment & (InplaceAlignment-1)) == 0, "Alignment option must be zero or power of two");
91 static const std::size_t final_alignment = InplaceAlignment ? InplaceAlignment : dtl::alignment_of<T>::value;
92 typename dtl::aligned_storage<sizeof(T)*N, final_alignment>::type storage;
95 template<class Options>
96 struct get_static_vector_opt
102 struct get_static_vector_opt<void>
104 typedef static_vector_null_opt type;
107 template <typename T, std::size_t Capacity, class Options>
108 struct get_static_vector_allocator
110 typedef typename get_static_vector_opt<Options>::type options_t;
111 typedef dtl::static_storage_allocator
114 , options_t::inplace_alignment
115 , options_t::throw_on_overflow
122 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
125 //!@brief A variable-size array container with fixed capacity.
127 //!static_vector is a sequence container like boost::container::vector with contiguous storage that can
128 //!change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.
130 //!A static_vector is a sequence that supports random access to elements, constant time insertion and
131 //!removal of elements at the end, and linear time insertion and removal of elements at the beginning or
132 //!in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity
133 //!because elements are stored within the object itself similarly to an array. However, objects are
134 //!initialized as they are inserted into static_vector unlike C arrays or std::array which must construct
135 //!all elements on instantiation. The behavior of static_vector enables the use of statically allocated
136 //!elements in cases with complex object lifetime requirements that would otherwise not be trivially
139 //!@par Error Handling
140 //! Insertion beyond the capacity result in throwing std::bad_alloc() if exceptions are enabled or
141 //! calling throw_bad_alloc() if not enabled.
143 //! std::out_of_range is thrown if out of bounds access is performed in <code>at()</code> if exceptions are
144 //! enabled, throw_out_of_range() if not enabled.
146 //!@tparam T The type of element that will be stored.
147 //!@tparam Capacity The maximum number of elements static_vector can store, fixed at compile time.
148 //!@tparam Options A type produced from \c boost::container::static_vector_options.
149 template <typename T, std::size_t Capacity, class Options BOOST_CONTAINER_DOCONLY(= void) >
151 : public vector<T, typename dtl::get_static_vector_allocator< T, Capacity, Options>::type>
154 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
155 typedef typename dtl::get_static_vector_allocator< T, Capacity, Options>::type allocator_type;
156 typedef vector<T, allocator_type > base_t;
158 BOOST_COPYABLE_AND_MOVABLE(static_vector)
160 template<class U, std::size_t OtherCapacity, class OtherOptions>
161 friend class static_vector;
164 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
167 //! @brief The type of elements stored in the container.
168 typedef typename base_t::value_type value_type;
169 //! @brief The unsigned integral type used by the container.
170 typedef typename base_t::size_type size_type;
171 //! @brief The pointers difference type.
172 typedef typename base_t::difference_type difference_type;
173 //! @brief The pointer type.
174 typedef typename base_t::pointer pointer;
175 //! @brief The const pointer type.
176 typedef typename base_t::const_pointer const_pointer;
177 //! @brief The value reference type.
178 typedef typename base_t::reference reference;
179 //! @brief The value const reference type.
180 typedef typename base_t::const_reference const_reference;
181 //! @brief The iterator type.
182 typedef typename base_t::iterator iterator;
183 //! @brief The const iterator type.
184 typedef typename base_t::const_iterator const_iterator;
185 //! @brief The reverse iterator type.
186 typedef typename base_t::reverse_iterator reverse_iterator;
187 //! @brief The const reverse iterator.
188 typedef typename base_t::const_reverse_iterator const_reverse_iterator;
190 //! @brief The capacity/max size of the container
191 static const size_type static_capacity = Capacity;
193 //! @brief Constructs an empty static_vector.
200 BOOST_CONTAINER_FORCEINLINE static_vector() BOOST_NOEXCEPT_OR_NOTHROW
204 //! @pre <tt>count <= capacity()</tt>
206 //! @brief Constructs a static_vector containing count value initialized values.
208 //! @param count The number of values which will be contained in the container.
211 //! If T's value initialization throws.
215 BOOST_CONTAINER_FORCEINLINE explicit static_vector(size_type count)
219 //! @pre <tt>count <= capacity()</tt>
221 //! @brief Constructs a static_vector containing count default initialized values.
223 //! @param count The number of values which will be contained in the container.
226 //! If T's default initialization throws.
232 //! Non-standard extension
233 BOOST_CONTAINER_FORCEINLINE static_vector(size_type count, default_init_t)
234 : base_t(count, default_init_t())
237 //! @pre <tt>count <= capacity()</tt>
239 //! @brief Constructs a static_vector containing count copies of value.
241 //! @param count The number of copies of a values that will be contained in the container.
242 //! @param value The value which will be used to copy construct values.
245 //! If T's copy constructor throws.
249 BOOST_CONTAINER_FORCEINLINE static_vector(size_type count, value_type const& value)
250 : base_t(count, value)
254 //! @li <tt>distance(first, last) <= capacity()</tt>
255 //! @li Iterator must meet the \c ForwardTraversalIterator concept.
257 //! @brief Constructs a static_vector containing copy of a range <tt>[first, last)</tt>.
259 //! @param first The iterator to the first element in range.
260 //! @param last The iterator to the one after the last element in range.
263 //! If T's constructor taking a dereferenced Iterator throws.
267 template <typename Iterator>
268 BOOST_CONTAINER_FORCEINLINE static_vector(Iterator first, Iterator last)
269 : base_t(first, last)
272 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
274 //! @li <tt>distance(il.begin(), il.end()) <= capacity()</tt>
276 //! @brief Constructs a static_vector containing copy of a range <tt>[il.begin(), il.end())</tt>.
278 //! @param il std::initializer_list with values to initialize vector.
281 //! If T's constructor taking a dereferenced std::initializer_list throws.
285 BOOST_CONTAINER_FORCEINLINE static_vector(std::initializer_list<value_type> il)
290 //! @brief Constructs a copy of other static_vector.
292 //! @param other The static_vector which content will be copied to this one.
295 //! If T's copy constructor throws.
299 BOOST_CONTAINER_FORCEINLINE static_vector(static_vector const& other)
303 BOOST_CONTAINER_FORCEINLINE static_vector(static_vector const& other, const allocator_type &)
307 BOOST_CONTAINER_FORCEINLINE static_vector(BOOST_RV_REF(static_vector) other, const allocator_type &)
308 BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<value_type>::value)
309 : base_t(BOOST_MOVE_BASE(base_t, other))
312 BOOST_CONTAINER_FORCEINLINE explicit static_vector(const allocator_type &)
316 //! @pre <tt>other.size() <= capacity()</tt>.
318 //! @brief Constructs a copy of other static_vector.
320 //! @param other The static_vector which content will be copied to this one.
323 //! If T's copy constructor throws.
327 template <std::size_t C, class O>
328 BOOST_CONTAINER_FORCEINLINE static_vector(static_vector<T, C, O> const& other)
332 //! @brief Move constructor. Moves Values stored in the other static_vector to this one.
334 //! @param other The static_vector which content will be moved to this one.
337 //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor throws.
338 //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor throws.
342 BOOST_CONTAINER_FORCEINLINE static_vector(BOOST_RV_REF(static_vector) other)
343 BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<value_type>::value)
344 : base_t(BOOST_MOVE_BASE(base_t, other))
347 //! @pre <tt>other.size() <= capacity()</tt>
349 //! @brief Move constructor. Moves Values stored in the other static_vector to this one.
351 //! @param other The static_vector which content will be moved to this one.
354 //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor throws.
355 //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor throws.
359 template <std::size_t C, class O>
360 BOOST_CONTAINER_FORCEINLINE static_vector(BOOST_RV_REF_BEG static_vector<T, C, O> BOOST_RV_REF_END other)
361 : base_t(BOOST_MOVE_BASE(typename static_vector<T BOOST_MOVE_I C>::base_t, other))
364 //! @brief Copy assigns Values stored in the other static_vector to this one.
366 //! @param other The static_vector which content will be copied to this one.
369 //! If T's copy constructor or copy assignment throws.
373 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(BOOST_COPY_ASSIGN_REF(static_vector) other)
375 return static_cast<static_vector&>(base_t::operator=(static_cast<base_t const&>(other)));
378 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
379 //! @brief Copy assigns Values stored in std::initializer_list to *this.
381 //! @param il The std::initializer_list which content will be copied to this one.
384 //! If T's copy constructor or copy assignment throws.
388 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(std::initializer_list<value_type> il)
389 { return static_cast<static_vector&>(base_t::operator=(il)); }
392 //! @pre <tt>other.size() <= capacity()</tt>
394 //! @brief Copy assigns Values stored in the other static_vector to this one.
396 //! @param other The static_vector which content will be copied to this one.
399 //! If T's copy constructor or copy assignment throws.
403 template <std::size_t C, class O>
404 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(static_vector<T, C, O> const& other)
406 return static_cast<static_vector&>(base_t::operator=
407 (static_cast<typename static_vector<T, C, O>::base_t const&>(other)));
410 //! @brief Move assignment. Moves Values stored in the other static_vector to this one.
412 //! @param other The static_vector which content will be moved to this one.
415 //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws.
416 //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws.
420 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(BOOST_RV_REF(static_vector) other)
421 BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_assignable<value_type>::value)
423 return static_cast<static_vector&>(base_t::operator=(BOOST_MOVE_BASE(base_t, other)));
426 //! @pre <tt>other.size() <= capacity()</tt>
428 //! @brief Move assignment. Moves Values stored in the other static_vector to this one.
430 //! @param other The static_vector which content will be moved to this one.
433 //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws.
434 //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws.
438 template <std::size_t C, class O>
439 BOOST_CONTAINER_FORCEINLINE static_vector & operator=(BOOST_RV_REF_BEG static_vector<T, C, O> BOOST_RV_REF_END other)
441 return static_cast<static_vector&>(base_t::operator=
442 (BOOST_MOVE_BASE(typename static_vector<T BOOST_MOVE_I C>::base_t, other)));
445 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
447 //! @brief Destructor. Destroys Values stored in this container.
456 //! @brief Swaps contents of the other static_vector and this one.
458 //! @param other The static_vector which content will be swapped with this one's content.
461 //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws,
462 //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws,
466 void swap(static_vector & other);
468 //! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt>
470 //! @brief Swaps contents of the other static_vector and this one.
472 //! @param other The static_vector which content will be swapped with this one's content.
475 //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws,
476 //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws,
480 template <std::size_t C, class O>
481 void swap(static_vector<T, C, O> & other);
483 //! @pre <tt>count <= capacity()</tt>
485 //! @brief Inserts or erases elements at the end such that
486 //! the size becomes count. New elements are value initialized.
488 //! @param count The number of elements which will be stored in the container.
491 //! If T's value initialization throws.
495 void resize(size_type count);
497 //! @pre <tt>count <= capacity()</tt>
499 //! @brief Inserts or erases elements at the end such that
500 //! the size becomes count. New elements are default initialized.
502 //! @param count The number of elements which will be stored in the container.
505 //! If T's default initialization throws.
511 //! Non-standard extension
512 void resize(size_type count, default_init_t);
514 //! @pre <tt>count <= capacity()</tt>
516 //! @brief Inserts or erases elements at the end such that
517 //! the size becomes count. New elements are copy constructed from value.
519 //! @param count The number of elements which will be stored in the container.
520 //! @param value The value used to copy construct the new element.
523 //! If T's copy constructor throws.
527 void resize(size_type count, value_type const& value);
529 //! @pre <tt>count <= capacity()</tt>
531 //! @brief This call has no effect because the Capacity of this container is constant.
533 //! @param count The number of elements which the container should be able to contain.
540 void reserve(size_type count) BOOST_NOEXCEPT_OR_NOTHROW;
542 //! @pre <tt>size() < capacity()</tt>
544 //! @brief Adds a copy of value at the end.
546 //! @param value The value used to copy construct the new element.
549 //! If T's copy constructor throws.
553 void push_back(value_type const& value);
555 //! @pre <tt>size() < capacity()</tt>
557 //! @brief Moves value to the end.
559 //! @param value The value to move construct the new element.
562 //! If T's move constructor throws.
566 void push_back(BOOST_RV_REF(value_type) value);
568 //! @pre <tt>!empty()</tt>
570 //! @brief Destroys last value and decreases the size.
573 //! Nothing by default.
580 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
581 //! @li <tt>size() < capacity()</tt>
583 //! @brief Inserts a copy of element at p.
585 //! @param p The position at which the new value will be inserted.
586 //! @param value The value used to copy construct the new element.
589 //! @li If T's copy constructor or copy assignment throws
590 //! @li If T's move constructor or move assignment throws.
593 //! Constant or linear.
594 iterator insert(const_iterator p, value_type const& value);
597 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
598 //! @li <tt>size() < capacity()</tt>
600 //! @brief Inserts a move-constructed element at p.
602 //! @param p The position at which the new value will be inserted.
603 //! @param value The value used to move construct the new element.
606 //! If T's move constructor or move assignment throws.
609 //! Constant or linear.
610 iterator insert(const_iterator p, BOOST_RV_REF(value_type) value);
613 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
614 //! @li <tt>size() + count <= capacity()</tt>
616 //! @brief Inserts a count copies of value at p.
618 //! @param p The position at which new elements will be inserted.
619 //! @param count The number of new elements which will be inserted.
620 //! @param value The value used to copy construct new elements.
623 //! @li If T's copy constructor or copy assignment throws.
624 //! @li If T's move constructor or move assignment throws.
628 iterator insert(const_iterator p, size_type count, value_type const& value);
631 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
632 //! @li <tt>distance(first, last) <= capacity()</tt>
633 //! @li \c Iterator must meet the \c ForwardTraversalIterator concept.
635 //! @brief Inserts a copy of a range <tt>[first, last)</tt> at p.
637 //! @param p The position at which new elements will be inserted.
638 //! @param first The iterator to the first element of a range used to construct new elements.
639 //! @param last The iterator to the one after the last element of a range used to construct new elements.
642 //! @li If T's constructor and assignment taking a dereferenced \c Iterator.
643 //! @li If T's move constructor or move assignment throws.
647 template <typename Iterator>
648 iterator insert(const_iterator p, Iterator first, Iterator last);
651 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
652 //! @li <tt>distance(il.begin(), il.end()) <= capacity()</tt>
654 //! @brief Inserts a copy of a range <tt>[il.begin(), il.end())</tt> at p.
656 //! @param p The position at which new elements will be inserted.
657 //! @param il The std::initializer_list which contains elements that will be inserted.
660 //! @li If T's constructor and assignment taking a dereferenced std::initializer_list iterator.
664 iterator insert(const_iterator p, std::initializer_list<value_type> il);
666 //! @pre \c p must be a valid iterator of \c *this in range <tt>[begin(), end())</tt>
668 //! @brief Erases T from p.
670 //! @param p The position of the element which will be erased from the container.
673 //! If T's move assignment throws.
677 iterator erase(const_iterator p);
680 //! @li \c first and \c last must define a valid range
681 //! @li iterators must be in range <tt>[begin(), end()]</tt>
683 //! @brief Erases Values from a range <tt>[first, last)</tt>.
685 //! @param first The position of the first element of a range which will be erased from the container.
686 //! @param last The position of the one after the last element of a range which will be erased from the container.
689 //! If T's move assignment throws.
693 iterator erase(const_iterator first, const_iterator last);
695 //! @pre <tt>distance(first, last) <= capacity()</tt>
697 //! @brief Assigns a range <tt>[first, last)</tt> of Values to this container.
699 //! @param first The iterator to the first element of a range used to construct new content of this container.
700 //! @param last The iterator to the one after the last element of a range used to construct new content of this container.
703 //! If T's copy constructor or copy assignment throws,
707 template <typename Iterator>
708 void assign(Iterator first, Iterator last);
710 //! @pre <tt>distance(il.begin(), il.end()) <= capacity()</tt>
712 //! @brief Assigns a range <tt>[il.begin(), il.end())</tt> of Values to this container.
714 //! @param il std::initializer_list with values used to construct new content of this container.
717 //! If T's copy constructor or copy assignment throws,
721 void assign(std::initializer_list<value_type> il);
723 //! @pre <tt>count <= capacity()</tt>
725 //! @brief Assigns a count copies of value to this container.
727 //! @param count The new number of elements which will be container in the container.
728 //! @param value The value which will be used to copy construct the new content.
731 //! If T's copy constructor or copy assignment throws.
735 void assign(size_type count, value_type const& value);
737 //! @pre <tt>size() < capacity()</tt>
739 //! @brief Inserts a T constructed with
740 //! \c std::forward<Args>(args)... in the end of the container.
742 //! @return A reference to the created object.
744 //! @param args The arguments of the constructor of the new element which will be created at the end of the container.
747 //! If in-place constructor throws or T's move constructor throws.
751 template<class ...Args>
752 reference emplace_back(Args &&...args);
755 //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>
756 //! @li <tt>size() < capacity()</tt>
758 //! @brief Inserts a T constructed with
759 //! \c std::forward<Args>(args)... before p
761 //! @param p The position at which new elements will be inserted.
762 //! @param args The arguments of the constructor of the new element.
765 //! If in-place constructor throws or if T's move constructor or move assignment throws.
768 //! Constant or linear.
769 template<class ...Args>
770 iterator emplace(const_iterator p, Args &&...args);
772 //! @brief Removes all elements from the container.
779 void clear() BOOST_NOEXCEPT_OR_NOTHROW;
781 //! @pre <tt>i < size()</tt>
783 //! @brief Returns reference to the i-th element.
785 //! @param i The element's index.
787 //! @return reference to the i-th element
788 //! from the beginning of the container.
791 //! \c std::out_of_range exception by default.
795 reference at(size_type i);
797 //! @pre <tt>i < size()</tt>
799 //! @brief Returns const reference to the i-th element.
801 //! @param i The element's index.
803 //! @return const reference to the i-th element
804 //! from the beginning of the container.
807 //! \c std::out_of_range exception by default.
811 const_reference at(size_type i) const;
813 //! @pre <tt>i < size()</tt>
815 //! @brief Returns reference to the i-th element.
817 //! @param i The element's index.
819 //! @return reference to the i-th element
820 //! from the beginning of the container.
823 //! Nothing by default.
827 reference operator[](size_type i);
829 //! @pre <tt>i < size()</tt>
831 //! @brief Returns const reference to the i-th element.
833 //! @param i The element's index.
835 //! @return const reference to the i-th element
836 //! from the beginning of the container.
839 //! Nothing by default.
843 const_reference operator[](size_type i) const;
845 //! @pre <tt>i =< size()</tt>
847 //! @brief Returns a iterator to the i-th element.
849 //! @param i The element's index.
851 //! @return a iterator to the i-th element.
854 //! Nothing by default.
858 iterator nth(size_type i);
860 //! @pre <tt>i =< size()</tt>
862 //! @brief Returns a const_iterator to the i-th element.
864 //! @param i The element's index.
866 //! @return a const_iterator to the i-th element.
869 //! Nothing by default.
873 const_iterator nth(size_type i) const;
875 //! @pre <tt>begin() <= p <= end()</tt>
877 //! @brief Returns the index of the element pointed by p.
879 //! @param p An iterator to the element.
881 //! @return The index of the element pointed by p.
884 //! Nothing by default.
888 size_type index_of(iterator p);
890 //! @pre <tt>begin() <= p <= end()</tt>
892 //! @brief Returns the index of the element pointed by p.
894 //! @param p A const_iterator to the element.
896 //! @return a const_iterator to the i-th element.
899 //! Nothing by default.
903 size_type index_of(const_iterator p) const;
907 //! @brief Returns reference to the first element.
909 //! @return reference to the first element
910 //! from the beginning of the container.
913 //! Nothing by default.
921 //! @brief Returns const reference to the first element.
923 //! @return const reference to the first element
924 //! from the beginning of the container.
927 //! Nothing by default.
931 const_reference front() const;
935 //! @brief Returns reference to the last element.
937 //! @return reference to the last element
938 //! from the beginning of the container.
941 //! Nothing by default.
949 //! @brief Returns const reference to the first element.
951 //! @return const reference to the last element
952 //! from the beginning of the container.
955 //! Nothing by default.
959 const_reference back() const;
961 //! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range.
962 //! For a non-empty vector <tt>data() == &front()</tt>.
969 T * data() BOOST_NOEXCEPT_OR_NOTHROW;
971 //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range.
972 //! For a non-empty vector <tt>data() == &front()</tt>.
979 const T * data() const BOOST_NOEXCEPT_OR_NOTHROW;
981 //! @brief Returns iterator to the first element.
983 //! @return iterator to the first element contained in the vector.
990 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
992 //! @brief Returns const iterator to the first element.
994 //! @return const_iterator to the first element contained in the vector.
1001 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
1003 //! @brief Returns const iterator to the first element.
1005 //! @return const_iterator to the first element contained in the vector.
1012 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1014 //! @brief Returns iterator to the one after the last element.
1016 //! @return iterator pointing to the one after the last element contained in the vector.
1023 iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
1025 //! @brief Returns const iterator to the one after the last element.
1027 //! @return const_iterator pointing to the one after the last element contained in the vector.
1034 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
1036 //! @brief Returns const iterator to the one after the last element.
1038 //! @return const_iterator pointing to the one after the last element contained in the vector.
1045 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
1047 //! @brief Returns reverse iterator to the first element of the reversed container.
1049 //! @return reverse_iterator pointing to the beginning
1050 //! of the reversed static_vector.
1057 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
1059 //! @brief Returns const reverse iterator to the first element of the reversed container.
1061 //! @return const_reverse_iterator pointing to the beginning
1062 //! of the reversed static_vector.
1069 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1071 //! @brief Returns const reverse iterator to the first element of the reversed container.
1073 //! @return const_reverse_iterator pointing to the beginning
1074 //! of the reversed static_vector.
1081 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1083 //! @brief Returns reverse iterator to the one after the last element of the reversed container.
1085 //! @return reverse_iterator pointing to the one after the last element
1086 //! of the reversed static_vector.
1093 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
1095 //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
1097 //! @return const_reverse_iterator pointing to the one after the last element
1098 //! of the reversed static_vector.
1105 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
1107 //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
1109 //! @return const_reverse_iterator pointing to the one after the last element
1110 //! of the reversed static_vector.
1117 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
1119 #endif //#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1121 //! @brief Returns container's capacity.
1123 //! @return container's capacity.
1130 BOOST_CONTAINER_FORCEINLINE static size_type capacity() BOOST_NOEXCEPT_OR_NOTHROW
1131 { return static_capacity; }
1133 //! @brief Returns container's capacity.
1135 //! @return container's capacity.
1142 BOOST_CONTAINER_FORCEINLINE static size_type max_size() BOOST_NOEXCEPT_OR_NOTHROW
1143 { return static_capacity; }
1145 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1147 //! @brief Returns the number of stored elements.
1149 //! @return Number of elements contained in the container.
1156 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
1158 //! @brief Queries if the container contains elements.
1160 //! @return true if the number of elements contained in the
1161 //! container is equal to 0.
1168 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
1171 BOOST_CONTAINER_FORCEINLINE friend void swap(static_vector &x, static_vector &y)
1176 #endif // BOOST_CONTAINER_DOXYGEN_INVOKED
1180 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1182 //! @brief Checks if contents of two static_vectors are equal.
1184 //! @ingroup static_vector_non_member
1186 //! @param x The first static_vector.
1187 //! @param y The second static_vector.
1189 //! @return \c true if containers have the same size and elements in both containers are equal.
1193 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1194 bool operator== (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
1196 //! @brief Checks if contents of two static_vectors are not equal.
1198 //! @ingroup static_vector_non_member
1200 //! @param x The first static_vector.
1201 //! @param y The second static_vector.
1203 //! @return \c true if containers have different size or elements in both containers are not equal.
1207 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1208 bool operator!= (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
1210 //! @brief Lexicographically compares static_vectors.
1212 //! @ingroup static_vector_non_member
1214 //! @param x The first static_vector.
1215 //! @param y The second static_vector.
1217 //! @return \c true if x compares lexicographically less than y.
1221 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1222 bool operator< (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
1224 //! @brief Lexicographically compares static_vectors.
1226 //! @ingroup static_vector_non_member
1228 //! @param x The first static_vector.
1229 //! @param y The second static_vector.
1231 //! @return \c true if y compares lexicographically less than x.
1235 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1236 bool operator> (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
1238 //! @brief Lexicographically compares static_vectors.
1240 //! @ingroup static_vector_non_member
1242 //! @param x The first static_vector.
1243 //! @param y The second static_vector.
1245 //! @return \c true if y don't compare lexicographically less than x.
1249 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1250 bool operator<= (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
1252 //! @brief Lexicographically compares static_vectors.
1254 //! @ingroup static_vector_non_member
1256 //! @param x The first static_vector.
1257 //! @param y The second static_vector.
1259 //! @return \c true if x don't compare lexicographically less than y.
1263 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1264 bool operator>= (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
1266 //! @brief Swaps contents of two static_vectors.
1268 //! This function calls static_vector::swap().
1270 //! @ingroup static_vector_non_member
1272 //! @param x The first static_vector.
1273 //! @param y The second static_vector.
1277 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1278 inline void swap(static_vector<V, C1, O1> & x, static_vector<V, C2, O2> & y);
1282 template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
1283 inline void swap(static_vector<V, C1, O1> & x, static_vector<V, C2, O2> & y
1284 , typename dtl::enable_if_c< C1 != C2>::type * = 0)
1289 #endif // BOOST_CONTAINER_DOXYGEN_INVOKED
1291 }} // namespace boost::container
1293 #include <boost/container/detail/config_end.hpp>
1295 #endif // BOOST_CONTAINER_STATIC_VECTOR_HPP