Chris@16: // Boost.Container static_vector Chris@16: // Chris@16: // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland. Chris@16: // Copyright (c) 2011-2013 Andrew Hundt. Chris@101: // Copyright (c) 2013-2014 Ion Gaztanaga Chris@16: // Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_CONTAINER_STATIC_VECTOR_HPP Chris@16: #define BOOST_CONTAINER_STATIC_VECTOR_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@16: Chris@101: #include Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: #include Chris@101: #endif Chris@16: Chris@16: namespace boost { namespace container { Chris@16: Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@101: Chris@16: namespace container_detail { Chris@16: Chris@16: template Chris@16: class static_storage_allocator Chris@16: { Chris@16: public: Chris@16: typedef T value_type; Chris@16: Chris@101: static_storage_allocator() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: {} Chris@16: Chris@101: static_storage_allocator(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW Chris@16: {} Chris@16: Chris@101: static_storage_allocator & operator=(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW Chris@16: {} Chris@16: Chris@101: T* internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return const_cast(static_cast(static_cast(&storage))); } Chris@16: Chris@101: T* internal_storage() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return static_cast(static_cast(&storage)); } Chris@16: Chris@16: static const std::size_t internal_capacity = N; Chris@16: Chris@16: typedef boost::container::container_detail::version_type version; Chris@16: Chris@101: friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return false; } Chris@16: Chris@101: friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return true; } Chris@16: Chris@16: private: Chris@101: typename aligned_storage::value>::type storage; Chris@16: }; Chris@16: Chris@16: } //namespace container_detail { Chris@16: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@101: //! Chris@101: //!@brief A variable-size array container with fixed capacity. Chris@101: //! Chris@101: //!static_vector is a sequence container like boost::container::vector with contiguous storage that can Chris@101: //!change in size, along with the static allocation, low overhead, and fixed capacity of boost::array. Chris@101: //! Chris@101: //!A static_vector is a sequence that supports random access to elements, constant time insertion and Chris@101: //!removal of elements at the end, and linear time insertion and removal of elements at the beginning or Chris@101: //!in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity Chris@101: //!because elements are stored within the object itself similarly to an array. However, objects are Chris@101: //!initialized as they are inserted into static_vector unlike C arrays or std::array which must construct Chris@101: //!all elements on instantiation. The behavior of static_vector enables the use of statically allocated Chris@101: //!elements in cases with complex object lifetime requirements that would otherwise not be trivially Chris@101: //!possible. Chris@101: //! Chris@101: //!@par Error Handling Chris@101: //! Insertion beyond the capacity result in throwing std::bad_alloc() if exceptions are enabled or Chris@101: //! calling throw_bad_alloc() if not enabled. Chris@101: //! Chris@101: //! std::out_of_range is thrown if out of bound access is performed in at() if exceptions are Chris@101: //! enabled, throw_out_of_range() if not enabled. Chris@101: //! Chris@101: //!@tparam Value The type of element that will be stored. Chris@101: //!@tparam Capacity The maximum number of elements static_vector can store, fixed at compile time. Chris@16: template Chris@16: class static_vector Chris@16: : public vector > Chris@16: { Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@101: typedef vector > base_t; Chris@16: Chris@101: BOOST_COPYABLE_AND_MOVABLE(static_vector) Chris@16: Chris@16: template Chris@16: friend class static_vector; Chris@16: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@101: Chris@16: public: Chris@16: //! @brief The type of elements stored in the container. Chris@16: typedef typename base_t::value_type value_type; Chris@16: //! @brief The unsigned integral type used by the container. Chris@16: typedef typename base_t::size_type size_type; Chris@16: //! @brief The pointers difference type. Chris@16: typedef typename base_t::difference_type difference_type; Chris@16: //! @brief The pointer type. Chris@16: typedef typename base_t::pointer pointer; Chris@16: //! @brief The const pointer type. Chris@16: typedef typename base_t::const_pointer const_pointer; Chris@16: //! @brief The value reference type. Chris@16: typedef typename base_t::reference reference; Chris@16: //! @brief The value const reference type. Chris@16: typedef typename base_t::const_reference const_reference; Chris@16: //! @brief The iterator type. Chris@16: typedef typename base_t::iterator iterator; Chris@16: //! @brief The const iterator type. Chris@16: typedef typename base_t::const_iterator const_iterator; Chris@16: //! @brief The reverse iterator type. Chris@16: typedef typename base_t::reverse_iterator reverse_iterator; Chris@16: //! @brief The const reverse iterator. Chris@16: typedef typename base_t::const_reverse_iterator const_reverse_iterator; Chris@16: Chris@16: //! @brief Constructs an empty static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: static_vector() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: : base_t() Chris@16: {} Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Constructs a static_vector containing count value initialized values. Chris@16: //! Chris@16: //! @param count The number of values which will be contained in the container. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! If Value's value initialization throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: explicit static_vector(size_type count) Chris@16: : base_t(count) Chris@16: {} Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@101: //! @brief Constructs a static_vector containing count default initialized values. Chris@16: //! Chris@16: //! @param count The number of values which will be contained in the container. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! If Value's default initialization throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: //! Chris@16: //! @par Note Chris@16: //! Non-standard extension Chris@16: static_vector(size_type count, default_init_t) Chris@16: : base_t(count, default_init_t()) Chris@16: {} Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Constructs a static_vector containing count copies of value. Chris@16: //! Chris@16: //! @param count The number of copies of a values that will be contained in the container. Chris@16: //! @param value The value which will be used to copy construct values. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: static_vector(size_type count, value_type const& value) Chris@16: : base_t(count, value) Chris@16: {} Chris@16: Chris@16: //! @pre Chris@16: //! @li distance(first, last) <= capacity() Chris@16: //! @li Iterator must meet the \c ForwardTraversalIterator concept. Chris@16: //! Chris@16: //! @brief Constructs a static_vector containing copy of a range [first, last). Chris@16: //! Chris@16: //! @param first The iterator to the first element in range. Chris@16: //! @param last The iterator to the one after the last element in range. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's constructor taking a dereferenced Iterator throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: static_vector(Iterator first, Iterator last) Chris@16: : base_t(first, last) Chris@16: {} Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! @pre Chris@101: //! @li distance(il.begin(), il.end()) <= capacity() Chris@101: //! Chris@101: //! @brief Constructs a static_vector containing copy of a range [il.begin(), il.end()). Chris@101: //! Chris@101: //! @param il std::initializer_list with values to initialize vector. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! If Value's constructor taking a dereferenced std::initializer_list throws. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Linear O(N). Chris@101: static_vector(std::initializer_list il) Chris@101: : base_t(il) Chris@101: {} Chris@101: #endif Chris@101: Chris@16: //! @brief Constructs a copy of other static_vector. Chris@16: //! Chris@16: //! @param other The static_vector which content will be copied to this one. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: static_vector(static_vector const& other) Chris@16: : base_t(other) Chris@16: {} Chris@16: Chris@16: //! @pre other.size() <= capacity(). Chris@16: //! Chris@16: //! @brief Constructs a copy of other static_vector. Chris@16: //! Chris@16: //! @param other The static_vector which content will be copied to this one. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@101: static_vector(static_vector const& other) Chris@101: : base_t(other) Chris@101: {} Chris@101: Chris@101: //! @brief Move constructor. Moves Values stored in the other static_vector to this one. Chris@101: //! Chris@101: //! @param other The static_vector which content will be moved to this one. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! @li If \c has_nothrow_move::value is \c true and Value's move constructor throws. Chris@101: //! @li If \c has_nothrow_move::value is \c false and Value's copy constructor throws. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Linear O(N). Chris@101: static_vector(BOOST_RV_REF(static_vector) other) Chris@101: : base_t(BOOST_MOVE_BASE(base_t, other)) Chris@101: {} Chris@101: Chris@101: //! @pre other.size() <= capacity() Chris@101: //! Chris@101: //! @brief Move constructor. Moves Values stored in the other static_vector to this one. Chris@101: //! Chris@101: //! @param other The static_vector which content will be moved to this one. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! @li If \c has_nothrow_move::value is \c true and Value's move constructor throws. Chris@101: //! @li If \c has_nothrow_move::value is \c false and Value's copy constructor throws. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Linear O(N). Chris@101: template Chris@101: static_vector(BOOST_RV_REF_BEG static_vector BOOST_RV_REF_END other) Chris@101: : base_t(BOOST_MOVE_BASE(typename static_vector::base_t, other)) Chris@101: {} Chris@16: Chris@16: //! @brief Copy assigns Values stored in the other static_vector to this one. Chris@16: //! Chris@16: //! @param other The static_vector which content will be copied to this one. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor or copy assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: static_vector & operator=(BOOST_COPY_ASSIGN_REF(static_vector) other) Chris@16: { Chris@101: return static_cast(base_t::operator=(static_cast(other))); Chris@16: } Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! @brief Copy assigns Values stored in std::initializer_list to *this. Chris@101: //! Chris@101: //! @param il The std::initializer_list which content will be copied to this one. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! If Value's copy constructor or copy assignment throws. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Linear O(N). Chris@101: static_vector & operator=(std::initializer_list il) Chris@101: { return static_cast(base_t::operator=(il)); } Chris@101: #endif Chris@101: Chris@16: //! @pre other.size() <= capacity() Chris@16: //! Chris@16: //! @brief Copy assigns Values stored in the other static_vector to this one. Chris@16: //! Chris@16: //! @param other The static_vector which content will be copied to this one. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor or copy assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: static_vector & operator=(static_vector const& other) Chris@16: { Chris@101: return static_cast(base_t::operator= Chris@101: (static_cast::base_t const&>(other))); Chris@16: } Chris@16: Chris@16: //! @brief Move assignment. Moves Values stored in the other static_vector to this one. Chris@16: //! Chris@16: //! @param other The static_vector which content will be moved to this one. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! @li If \c has_nothrow_move::value is \c true and Value's move constructor or move assignment throws. Chris@101: //! @li If \c has_nothrow_move::value is \c false and Value's copy constructor or copy assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: static_vector & operator=(BOOST_RV_REF(static_vector) other) Chris@16: { Chris@101: return static_cast(base_t::operator=(BOOST_MOVE_BASE(base_t, other))); Chris@16: } Chris@16: Chris@16: //! @pre other.size() <= capacity() Chris@16: //! Chris@16: //! @brief Move assignment. Moves Values stored in the other static_vector to this one. Chris@16: //! Chris@16: //! @param other The static_vector which content will be moved to this one. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! @li If \c has_nothrow_move::value is \c true and Value's move constructor or move assignment throws. Chris@101: //! @li If \c has_nothrow_move::value is \c false and Value's copy constructor or copy assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: static_vector & operator=(BOOST_RV_REF_BEG static_vector BOOST_RV_REF_END other) Chris@16: { Chris@101: return static_cast(base_t::operator= Chris@101: (BOOST_MOVE_BASE(typename static_vector::base_t, other))); Chris@16: } Chris@16: Chris@16: #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: //! @brief Destructor. Destroys Values stored in this container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: ~static_vector(); Chris@16: Chris@16: //! @brief Swaps contents of the other static_vector and this one. Chris@16: //! Chris@16: //! @param other The static_vector which content will be swapped with this one's content. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! @li If \c has_nothrow_move::value is \c true and Value's move constructor or move assignment throws, Chris@101: //! @li If \c has_nothrow_move::value is \c false and Value's copy constructor or copy assignment throws, Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void swap(static_vector & other); Chris@16: Chris@16: //! @pre other.size() <= capacity() && size() <= other.capacity() Chris@16: //! Chris@16: //! @brief Swaps contents of the other static_vector and this one. Chris@16: //! Chris@16: //! @param other The static_vector which content will be swapped with this one's content. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! @li If \c has_nothrow_move::value is \c true and Value's move constructor or move assignment throws, Chris@101: //! @li If \c has_nothrow_move::value is \c false and Value's copy constructor or copy assignment throws, Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: void swap(static_vector & other); Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Inserts or erases elements at the end such that Chris@16: //! the size becomes count. New elements are value initialized. Chris@16: //! Chris@16: //! @param count The number of elements which will be stored in the container. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! If Value's value initialization throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void resize(size_type count); Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Inserts or erases elements at the end such that Chris@16: //! the size becomes count. New elements are default initialized. Chris@16: //! Chris@16: //! @param count The number of elements which will be stored in the container. Chris@16: //! Chris@16: //! @par Throws Chris@101: //! If Value's default initialization throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: //! Chris@16: //! @par Note Chris@16: //! Non-standard extension Chris@16: void resize(size_type count, default_init_t); Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Inserts or erases elements at the end such that Chris@16: //! the size becomes count. New elements are copy constructed from value. Chris@16: //! Chris@16: //! @param count The number of elements which will be stored in the container. Chris@16: //! @param value The value used to copy construct the new element. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void resize(size_type count, value_type const& value); Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief This call has no effect because the Capacity of this container is constant. Chris@16: //! Chris@16: //! @param count The number of elements which the container should be able to contain. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@101: void reserve(size_type count) BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @pre size() < capacity() Chris@16: //! Chris@16: //! @brief Adds a copy of value at the end. Chris@16: //! Chris@16: //! @param value The value used to copy construct the new element. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: void push_back(value_type const& value); Chris@16: Chris@16: //! @pre size() < capacity() Chris@16: //! Chris@16: //! @brief Moves value to the end. Chris@16: //! Chris@16: //! @param value The value to move construct the new element. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's move constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: void push_back(BOOST_RV_REF(value_type) value); Chris@16: Chris@16: //! @pre !empty() Chris@16: //! Chris@16: //! @brief Destroys last value and decreases the size. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: void pop_back(); Chris@16: Chris@16: //! @pre Chris@101: //! @li \c p must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li size() < capacity() Chris@16: //! Chris@101: //! @brief Inserts a copy of element at p. Chris@16: //! Chris@101: //! @param p The position at which the new value will be inserted. Chris@101: //! @param value The value used to copy construct the new element. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! @li If Value's copy constructor or copy assignment throws Chris@16: //! @li If Value's move constructor or move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant or linear. Chris@101: iterator insert(const_iterator p, value_type const& value); Chris@16: Chris@16: //! @pre Chris@101: //! @li \c p must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li size() < capacity() Chris@16: //! Chris@101: //! @brief Inserts a move-constructed element at p. Chris@16: //! Chris@101: //! @param p The position at which the new value will be inserted. Chris@101: //! @param value The value used to move construct the new element. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's move constructor or move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant or linear. Chris@101: iterator insert(const_iterator p, BOOST_RV_REF(value_type) value); Chris@16: Chris@16: //! @pre Chris@101: //! @li \c p must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li size() + count <= capacity() Chris@16: //! Chris@101: //! @brief Inserts a count copies of value at p. Chris@16: //! Chris@101: //! @param p The position at which new elements will be inserted. Chris@101: //! @param count The number of new elements which will be inserted. Chris@101: //! @param value The value used to copy construct new elements. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! @li If Value's copy constructor or copy assignment throws. Chris@16: //! @li If Value's move constructor or move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@101: iterator insert(const_iterator p, size_type count, value_type const& value); Chris@16: Chris@16: //! @pre Chris@101: //! @li \c p must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li distance(first, last) <= capacity() Chris@16: //! @li \c Iterator must meet the \c ForwardTraversalIterator concept. Chris@16: //! Chris@101: //! @brief Inserts a copy of a range [first, last) at p. Chris@16: //! Chris@101: //! @param p The position at which new elements will be inserted. Chris@101: //! @param first The iterator to the first element of a range used to construct new elements. Chris@101: //! @param last The iterator to the one after the last element of a range used to construct new elements. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! @li If Value's constructor and assignment taking a dereferenced \c Iterator. Chris@16: //! @li If Value's move constructor or move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@101: iterator insert(const_iterator p, Iterator first, Iterator last); Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! @pre Chris@101: //! @li \c p must be a valid iterator of \c *this in range [begin(), end()]. Chris@101: //! @li distance(il.begin(), il.end()) <= capacity() Chris@16: //! Chris@101: //! @brief Inserts a copy of a range [il.begin(), il.end()) at p. Chris@16: //! Chris@101: //! @param p The position at which new elements will be inserted. Chris@101: //! @param il The std::initializer_list which contains elements that will be inserted. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! @li If Value's constructor and assignment taking a dereferenced std::initializer_list iterator. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Linear O(N). Chris@101: iterator insert(const_iterator p, std::initializer_list il); Chris@101: #endif Chris@101: Chris@101: //! @pre \c p must be a valid iterator of \c *this in range [begin(), end()) Chris@101: //! Chris@101: //! @brief Erases Value from p. Chris@101: //! Chris@101: //! @param p The position of the element which will be erased from the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@101: iterator erase(const_iterator p); Chris@16: Chris@16: //! @pre Chris@16: //! @li \c first and \c last must define a valid range Chris@16: //! @li iterators must be in range [begin(), end()] Chris@16: //! Chris@16: //! @brief Erases Values from a range [first, last). Chris@16: //! Chris@16: //! @param first The position of the first element of a range which will be erased from the container. Chris@16: //! @param last The position of the one after the last element of a range which will be erased from the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@101: iterator erase(const_iterator first, const_iterator last); Chris@16: Chris@16: //! @pre distance(first, last) <= capacity() Chris@16: //! Chris@16: //! @brief Assigns a range [first, last) of Values to this container. Chris@16: //! Chris@16: //! @param first The iterator to the first element of a range used to construct new content of this container. Chris@16: //! @param last The iterator to the one after the last element of a range used to construct new content of this container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor or copy assignment throws, Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: void assign(Iterator first, Iterator last); Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! @pre distance(il.begin(), il.end()) <= capacity() Chris@101: //! Chris@101: //! @brief Assigns a range [il.begin(), il.end()) of Values to this container. Chris@101: //! Chris@101: //! @param first std::initializer_list with values used to construct new content of this container. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! If Value's copy constructor or copy assignment throws, Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Linear O(N). Chris@101: void assign(std::initializer_list il); Chris@101: #endif Chris@101: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Assigns a count copies of value to this container. Chris@16: //! Chris@16: //! @param count The new number of elements which will be container in the container. Chris@16: //! @param value The value which will be used to copy construct the new content. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor or copy assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void assign(size_type count, value_type const& value); Chris@16: Chris@16: //! @pre size() < capacity() Chris@16: //! Chris@16: //! @brief Inserts a Value constructed with Chris@16: //! \c std::forward(args)... in the end of the container. Chris@16: //! Chris@16: //! @param args The arguments of the constructor of the new element which will be created at the end of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If in-place constructor throws or Value's move constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: template Chris@16: void emplace_back(Args &&...args); Chris@16: Chris@16: //! @pre Chris@101: //! @li \c p must be a valid iterator of \c *this in range [begin(), end()] Chris@16: //! @li size() < capacity() Chris@16: //! Chris@16: //! @brief Inserts a Value constructed with Chris@101: //! \c std::forward(args)... before p Chris@16: //! Chris@101: //! @param p The position at which new elements will be inserted. Chris@101: //! @param args The arguments of the constructor of the new element. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If in-place constructor throws or if Value's move constructor or move assignment throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant or linear. Chris@16: template Chris@101: iterator emplace(const_iterator p, Args &&...args); Chris@16: Chris@16: //! @brief Removes all elements from the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: void clear() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @pre i < size() Chris@16: //! Chris@16: //! @brief Returns reference to the i-th element. Chris@16: //! Chris@16: //! @param i The element's index. Chris@16: //! Chris@16: //! @return reference to the i-th element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! \c std::out_of_range exception by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: reference at(size_type i); Chris@16: Chris@16: //! @pre i < size() Chris@16: //! Chris@16: //! @brief Returns const reference to the i-th element. Chris@16: //! Chris@16: //! @param i The element's index. Chris@16: //! Chris@16: //! @return const reference to the i-th element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! \c std::out_of_range exception by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: const_reference at(size_type i) const; Chris@16: Chris@16: //! @pre i < size() Chris@16: //! Chris@16: //! @brief Returns reference to the i-th element. Chris@16: //! Chris@16: //! @param i The element's index. Chris@16: //! Chris@16: //! @return reference to the i-th element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: reference operator[](size_type i); Chris@16: Chris@16: //! @pre i < size() Chris@16: //! Chris@16: //! @brief Returns const reference to the i-th element. Chris@16: //! Chris@16: //! @param i The element's index. Chris@16: //! Chris@16: //! @return const reference to the i-th element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: const_reference operator[](size_type i) const; Chris@16: Chris@101: //! @pre i =< size() Chris@101: //! Chris@101: //! @brief Returns a iterator to the i-th element. Chris@101: //! Chris@101: //! @param i The element's index. Chris@101: //! Chris@101: //! @return a iterator to the i-th element. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! Nothing by default. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Constant O(1). Chris@101: iterator nth(size_type i); Chris@101: Chris@101: //! @pre i =< size() Chris@101: //! Chris@101: //! @brief Returns a const_iterator to the i-th element. Chris@101: //! Chris@101: //! @param i The element's index. Chris@101: //! Chris@101: //! @return a const_iterator to the i-th element. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! Nothing by default. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Constant O(1). Chris@101: const_iterator nth(size_type i) const; Chris@101: Chris@101: //! @pre begin() <= p <= end() Chris@101: //! Chris@101: //! @brief Returns the index of the element pointed by p. Chris@101: //! Chris@101: //! @param i The element's index. Chris@101: //! Chris@101: //! @return The index of the element pointed by p. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! Nothing by default. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Constant O(1). Chris@101: size_type index_of(iterator p); Chris@101: Chris@101: //! @pre begin() <= p <= end() Chris@101: //! Chris@101: //! @brief Returns the index of the element pointed by p. Chris@101: //! Chris@101: //! @param i The index of the element pointed by p. Chris@101: //! Chris@101: //! @return a const_iterator to the i-th element. Chris@101: //! Chris@101: //! @par Throws Chris@101: //! Nothing by default. Chris@101: //! Chris@101: //! @par Complexity Chris@101: //! Constant O(1). Chris@101: size_type index_of(const_iterator p) const; Chris@101: Chris@16: //! @pre \c !empty() Chris@16: //! Chris@16: //! @brief Returns reference to the first element. Chris@16: //! Chris@16: //! @return reference to the first element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: reference front(); Chris@16: Chris@16: //! @pre \c !empty() Chris@16: //! Chris@16: //! @brief Returns const reference to the first element. Chris@16: //! Chris@16: //! @return const reference to the first element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: const_reference front() const; Chris@16: Chris@16: //! @pre \c !empty() Chris@16: //! Chris@16: //! @brief Returns reference to the last element. Chris@16: //! Chris@16: //! @return reference to the last element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: reference back(); Chris@16: Chris@16: //! @pre \c !empty() Chris@16: //! Chris@16: //! @brief Returns const reference to the first element. Chris@16: //! Chris@16: //! @return const reference to the last element Chris@16: //! from the beginning of the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing by default. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: const_reference back() const; Chris@16: Chris@16: //! @brief Pointer such that [data(), data() + size()) is a valid range. Chris@16: //! For a non-empty vector data() == &front(). Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: Value * data() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Const pointer such that [data(), data() + size()) is a valid range. Chris@16: //! For a non-empty vector data() == &front(). Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const Value * data() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns iterator to the first element. Chris@16: //! Chris@16: //! @return iterator to the first element contained in the vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: iterator begin() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const iterator to the first element. Chris@16: //! Chris@16: //! @return const_iterator to the first element contained in the vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const iterator to the first element. Chris@16: //! Chris@16: //! @return const_iterator to the first element contained in the vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns iterator to the one after the last element. Chris@16: //! Chris@16: //! @return iterator pointing to the one after the last element contained in the vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: iterator end() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const iterator to the one after the last element. Chris@16: //! Chris@16: //! @return const_iterator pointing to the one after the last element contained in the vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const iterator to the one after the last element. Chris@16: //! Chris@16: //! @return const_iterator pointing to the one after the last element contained in the vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns reverse iterator to the first element of the reversed container. Chris@16: //! Chris@16: //! @return reverse_iterator pointing to the beginning Chris@16: //! of the reversed static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const reverse iterator to the first element of the reversed container. Chris@16: //! Chris@16: //! @return const_reverse_iterator pointing to the beginning Chris@16: //! of the reversed static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const reverse iterator to the first element of the reversed container. Chris@16: //! Chris@16: //! @return const_reverse_iterator pointing to the beginning Chris@16: //! of the reversed static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns reverse iterator to the one after the last element of the reversed container. Chris@16: //! Chris@16: //! @return reverse_iterator pointing to the one after the last element Chris@16: //! of the reversed static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const reverse iterator to the one after the last element of the reversed container. Chris@16: //! Chris@16: //! @return const_reverse_iterator pointing to the one after the last element Chris@16: //! of the reversed static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns const reverse iterator to the one after the last element of the reversed container. Chris@16: //! Chris@16: //! @return const_reverse_iterator pointing to the one after the last element Chris@16: //! of the reversed static_vector. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns container's capacity. Chris@16: //! Chris@16: //! @return container's capacity. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: static size_type capacity() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns container's capacity. Chris@16: //! Chris@16: //! @return container's capacity. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: static size_type max_size() BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Returns the number of stored elements. Chris@16: //! Chris@16: //! @return Number of elements contained in the container. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: size_type size() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: Chris@16: //! @brief Queries if the container contains elements. Chris@16: //! Chris@16: //! @return true if the number of elements contained in the Chris@16: //! container is equal to 0. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@101: bool empty() const BOOST_NOEXCEPT_OR_NOTHROW; Chris@16: #else Chris@16: Chris@16: friend void swap(static_vector &x, static_vector &y) Chris@16: { Chris@16: x.swap(y); Chris@16: } Chris@16: Chris@16: #endif // BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: }; Chris@16: Chris@16: #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: //! @brief Checks if contents of two static_vectors are equal. Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @return \c true if containers have the same size and elements in both containers are equal. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: bool operator== (static_vector const& x, static_vector const& y); Chris@16: Chris@16: //! @brief Checks if contents of two static_vectors are not equal. Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @return \c true if containers have different size or elements in both containers are not equal. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: bool operator!= (static_vector const& x, static_vector const& y); Chris@16: Chris@16: //! @brief Lexicographically compares static_vectors. Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @return \c true if x compares lexicographically less than y. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: bool operator< (static_vector const& x, static_vector const& y); Chris@16: Chris@16: //! @brief Lexicographically compares static_vectors. Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @return \c true if y compares lexicographically less than x. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: bool operator> (static_vector const& x, static_vector const& y); Chris@16: Chris@16: //! @brief Lexicographically compares static_vectors. Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @return \c true if y don't compare lexicographically less than x. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: bool operator<= (static_vector const& x, static_vector const& y); Chris@16: Chris@16: //! @brief Lexicographically compares static_vectors. Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @return \c true if x don't compare lexicographically less than y. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: bool operator>= (static_vector const& x, static_vector const& y); Chris@16: Chris@16: //! @brief Swaps contents of two static_vectors. Chris@16: //! Chris@16: //! This function calls static_vector::swap(). Chris@16: //! Chris@16: //! @ingroup static_vector_non_member Chris@16: //! Chris@16: //! @param x The first static_vector. Chris@16: //! @param y The second static_vector. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: inline void swap(static_vector & x, static_vector & y); Chris@16: Chris@16: #else Chris@16: Chris@16: template Chris@16: inline void swap(static_vector & x, static_vector & y Chris@16: , typename container_detail::enable_if_c< C1 != C2>::type * = 0) Chris@16: { Chris@16: x.swap(y); Chris@16: } Chris@16: Chris@16: #endif // BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: }} // namespace boost::container Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_CONTAINER_STATIC_VECTOR_HPP