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@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@16: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace container { Chris@16: 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@16: static_storage_allocator() BOOST_CONTAINER_NOEXCEPT Chris@16: {} Chris@16: Chris@16: static_storage_allocator(const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT Chris@16: {} Chris@16: Chris@16: static_storage_allocator & operator=(const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT Chris@16: {} Chris@16: Chris@16: T* internal_storage() const BOOST_CONTAINER_NOEXCEPT Chris@16: { return const_cast(static_cast(static_cast(&storage))); } Chris@16: Chris@16: T* internal_storage() BOOST_CONTAINER_NOEXCEPT 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@16: friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT Chris@16: { return false; } Chris@16: Chris@16: friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT Chris@16: { return true; } Chris@16: Chris@16: private: Chris@16: typename boost::aligned_storage Chris@16: ::value>::type storage; Chris@16: }; Chris@16: Chris@16: } //namespace container_detail { Chris@16: Chris@16: /** Chris@16: * @defgroup static_vector_non_member static_vector non-member functions Chris@16: */ Chris@16: Chris@16: /** Chris@16: * @brief A variable-size array container with fixed capacity. Chris@16: * Chris@16: * static_vector is a sequence container like boost::container::vector with contiguous storage that can Chris@16: * change in size, along with the static allocation, low overhead, and fixed capacity of boost::array. Chris@16: * Chris@16: * A static_vector is a sequence that supports random access to elements, constant time insertion and Chris@16: * removal of elements at the end, and linear time insertion and removal of elements at the beginning or Chris@16: * in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity Chris@16: * because elements are stored within the object itself similarly to an array. However, objects are Chris@16: * initialized as they are inserted into static_vector unlike C arrays or std::array which must construct Chris@16: * all elements on instantiation. The behavior of static_vector enables the use of statically allocated Chris@16: * elements in cases with complex object lifetime requirements that would otherwise not be trivially Chris@16: * possible. Chris@16: * Chris@16: * @par Error Handling Chris@16: * Insertion beyond the capacity result in throwing std::bad_alloc() if exceptions are enabled or Chris@16: * calling throw_bad_alloc() if not enabled. Chris@16: * Chris@16: * std::out_of_range is thrown if out of bound access is performed in `at()` if exceptions are Chris@16: * enabled, throw_out_of_range() if not enabled. Chris@16: * Chris@16: * @tparam Value The type of element that will be stored. Chris@16: * @tparam Capacity The maximum number of elements static_vector can store, fixed at compile time. Chris@16: */ Chris@16: template Chris@16: class static_vector Chris@16: : public vector > Chris@16: { Chris@16: typedef vector > base_t; Chris@16: Chris@16: BOOST_COPYABLE_AND_MOVABLE(static_vector) Chris@16: Chris@16: template Chris@16: friend class static_vector; Chris@16: 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@16: static_vector() BOOST_CONTAINER_NOEXCEPT 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@16: //! If Value's default constructor 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@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@16: //! If Value's default constructor 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@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@16: static_vector(static_vector const& other) : base_t(other) {} 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@16: base_t::operator=(static_cast(other)); Chris@16: return *this; Chris@16: } Chris@16: 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: // TEMPORARY WORKAROUND Chris@16: #if defined(BOOST_NO_RVALUE_REFERENCES) Chris@16: static_vector & operator=(::boost::rv< static_vector > const& other) Chris@16: #else Chris@16: static_vector & operator=(static_vector const& other) Chris@16: #endif Chris@16: { Chris@16: base_t::operator=(static_cast const&>(other)); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: //! @brief Move constructor. 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@16: //! @li If \c boost::has_nothrow_move::value is \c true and Value's move constructor throws. Chris@16: //! @li If \c boost::has_nothrow_move::value is \c false and Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: static_vector(BOOST_RV_REF(static_vector) other) Chris@16: : base_t(boost::move(static_cast(other))) Chris@16: {} Chris@16: Chris@16: //! @pre other.size() <= capacity() Chris@16: //! Chris@16: //! @brief Move constructor. 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@16: //! @li If \c boost::has_nothrow_move::value is \c true and Value's move constructor throws. Chris@16: //! @li If \c boost::has_nothrow_move::value is \c false and Value's copy constructor throws. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: static_vector(BOOST_RV_REF_BEG static_vector BOOST_RV_REF_END other) Chris@16: : base_t(boost::move(static_cast::base_t&>(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@16: //! @li If \c boost::has_nothrow_move::value is \c true and Value's move constructor or move assignment throws. Chris@16: //! @li If \c boost::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@16: base_t::operator=(boost::move(static_cast(other))); Chris@16: return *this; 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@16: //! @li If \c boost::has_nothrow_move::value is \c true and Value's move constructor or move assignment throws. Chris@16: //! @li If \c boost::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@16: base_t::operator=(boost::move(static_cast::base_t&>(other))); Chris@16: return *this; 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@16: //! @li If \c boost::has_nothrow_move::value is \c true and Value's move constructor or move assignment throws, Chris@16: //! @li If \c boost::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@16: //! @li If \c boost::has_nothrow_move::value is \c true and Value's move constructor or move assignment throws, Chris@16: //! @li If \c boost::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@16: //! If Value's default constructor 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@16: //! If Value's default constructor 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@16: void reserve(size_type count) BOOST_CONTAINER_NOEXCEPT; 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@16: //! @li \c position must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li size() < capacity() Chris@16: //! Chris@16: //! @brief Inserts a copy of element at position. Chris@16: //! Chris@16: //! @param position The position at which the new value will be inserted. Chris@16: //! @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@16: iterator insert(iterator position, value_type const& value); Chris@16: Chris@16: //! @pre Chris@16: //! @li \c position must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li size() < capacity() Chris@16: //! Chris@16: //! @brief Inserts a move-constructed element at position. Chris@16: //! Chris@16: //! @param position The position at which the new value will be inserted. Chris@16: //! @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@16: iterator insert(iterator position, BOOST_RV_REF(value_type) value); Chris@16: Chris@16: //! @pre Chris@16: //! @li \c position must be a valid iterator of \c *this in range [begin(), end()]. Chris@16: //! @li size() + count <= capacity() Chris@16: //! Chris@16: //! @brief Inserts a count copies of value at position. Chris@16: //! Chris@16: //! @param position The position at which new elements will be inserted. Chris@16: //! @param count The number of new elements which will be inserted. Chris@16: //! @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@16: iterator insert(iterator position, size_type count, value_type const& value); Chris@16: Chris@16: //! @pre Chris@16: //! @li \c position 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@16: //! @brief Inserts a copy of a range [first, last) at position. Chris@16: //! Chris@16: //! @param position The position at which new elements will be inserted. Chris@16: //! @param first The iterator to the first element of a range used to construct new elements. Chris@16: //! @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@16: iterator insert(iterator position, Iterator first, Iterator last); Chris@16: Chris@16: //! @pre \c position must be a valid iterator of \c *this in range [begin(), end()) Chris@16: //! Chris@16: //! @brief Erases Value from position. Chris@16: //! Chris@16: //! @param position 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@16: iterator erase(iterator position); 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@16: iterator erase(iterator first, 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@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@16: //! @li \c position 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@16: //! \c std::forward(args)... before position Chris@16: //! Chris@16: //! @param position The position at which new elements will be inserted. Chris@16: //! @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@16: iterator emplace(iterator position, 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@16: void clear() BOOST_CONTAINER_NOEXCEPT; 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@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@16: Value * data() BOOST_CONTAINER_NOEXCEPT; 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@16: const Value * data() const BOOST_CONTAINER_NOEXCEPT; 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@16: iterator begin() BOOST_CONTAINER_NOEXCEPT; 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@16: const_iterator begin() const BOOST_CONTAINER_NOEXCEPT; 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@16: const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT; 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@16: iterator end() BOOST_CONTAINER_NOEXCEPT; 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@16: const_iterator end() const BOOST_CONTAINER_NOEXCEPT; 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@16: const_iterator cend() const BOOST_CONTAINER_NOEXCEPT; 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@16: reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT; 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@16: const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT; 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@16: const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT; 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@16: reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT; 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@16: const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT; 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@16: const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT; 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@16: static size_type capacity() BOOST_CONTAINER_NOEXCEPT; 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@16: static size_type max_size() BOOST_CONTAINER_NOEXCEPT; 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@16: size_type size() const BOOST_CONTAINER_NOEXCEPT; 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@16: bool empty() const BOOST_CONTAINER_NOEXCEPT; 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