diff options
Diffstat (limited to 'boost/container/static_vector.hpp')
-rw-r--r-- | boost/container/static_vector.hpp | 170 |
1 files changed, 118 insertions, 52 deletions
diff --git a/boost/container/static_vector.hpp b/boost/container/static_vector.hpp index 1ae80114b3..c36832dfa3 100644 --- a/boost/container/static_vector.hpp +++ b/boost/container/static_vector.hpp @@ -11,14 +11,23 @@ #ifndef BOOST_CONTAINER_STATIC_VECTOR_HPP #define BOOST_CONTAINER_STATIC_VECTOR_HPP -#if defined(_MSC_VER) +#ifndef BOOST_CONFIG_HPP +# include <boost/config.hpp> +#endif + +#if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include <boost/container/detail/config_begin.hpp> - +#include <boost/container/detail/workaround.hpp> +#include <boost/container/detail/type_traits.hpp> #include <boost/container/vector.hpp> -#include <boost/aligned_storage.hpp> + +#include <cstddef> +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include <initializer_list> +#endif namespace boost { namespace container { @@ -32,34 +41,33 @@ class static_storage_allocator public: typedef T value_type; - static_storage_allocator() BOOST_CONTAINER_NOEXCEPT + static_storage_allocator() BOOST_NOEXCEPT_OR_NOTHROW {} - static_storage_allocator(const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT + static_storage_allocator(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW {} - static_storage_allocator & operator=(const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT + static_storage_allocator & operator=(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW {} - T* internal_storage() const BOOST_CONTAINER_NOEXCEPT + T* internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW { return const_cast<T*>(static_cast<const T*>(static_cast<const void*>(&storage))); } - T* internal_storage() BOOST_CONTAINER_NOEXCEPT + T* internal_storage() BOOST_NOEXCEPT_OR_NOTHROW { return static_cast<T*>(static_cast<void*>(&storage)); } static const std::size_t internal_capacity = N; typedef boost::container::container_detail::version_type<static_storage_allocator, 0> version; - friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT + friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW { return false; } - friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_CONTAINER_NOEXCEPT + friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW { return true; } private: - typename boost::aligned_storage - <sizeof(T)*N, boost::alignment_of<T>::value>::type storage; + typename aligned_storage<sizeof(T)*N, alignment_of<T>::value>::type storage; }; } //namespace container_detail { @@ -135,7 +143,7 @@ public: //! //! @par Complexity //! Constant O(1). - static_vector() BOOST_CONTAINER_NOEXCEPT + static_vector() BOOST_NOEXCEPT_OR_NOTHROW : base_t() {} @@ -259,13 +267,13 @@ public: //! @param other The static_vector which content will be moved to this one. //! //! @par Throws - //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws. - //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws. + //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor throws. + //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor throws. //! //! @par Complexity //! Linear O(N). static_vector(BOOST_RV_REF(static_vector) other) - : base_t(boost::move(static_cast<base_t&>(other))) + : base_t(BOOST_MOVE_BASE(base_t, other)) {} //! @pre <tt>other.size() <= capacity()</tt> @@ -275,14 +283,14 @@ public: //! @param other The static_vector which content will be moved to this one. //! //! @par Throws - //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws. - //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws. + //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor throws. + //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor throws. //! //! @par Complexity //! Linear O(N). template <std::size_t C> static_vector(BOOST_RV_REF_BEG static_vector<value_type, C> BOOST_RV_REF_END other) - : base_t(boost::move(static_cast<typename static_vector<value_type, C>::base_t&>(other))) + : base_t(BOOST_MOVE_BASE(typename static_vector<value_type BOOST_MOVE_I C>::base_t, other)) {} //! @brief Copy assigns Values stored in the other static_vector to this one. @@ -310,9 +318,7 @@ public: //! @par Complexity //! Linear O(N). static_vector & operator=(std::initializer_list<value_type> il) - { - return static_cast<static_vector&>(base_t::operator=(il)); - } + { return static_cast<static_vector&>(base_t::operator=(il)); } #endif //! @pre <tt>other.size() <= capacity()</tt> @@ -338,14 +344,14 @@ public: //! @param other The static_vector which content will be moved to this one. //! //! @par Throws - //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws. - //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws. + //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws. + //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws. //! //! @par Complexity //! Linear O(N). static_vector & operator=(BOOST_RV_REF(static_vector) other) { - return static_cast<static_vector&>(base_t::operator=(boost::move(static_cast<base_t&>(other)))); + return static_cast<static_vector&>(base_t::operator=(BOOST_MOVE_BASE(base_t, other))); } //! @pre <tt>other.size() <= capacity()</tt> @@ -355,8 +361,8 @@ public: //! @param other The static_vector which content will be moved to this one. //! //! @par Throws - //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws. - //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws. + //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws. + //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws. //! //! @par Complexity //! Linear O(N). @@ -364,7 +370,7 @@ public: static_vector & operator=(BOOST_RV_REF_BEG static_vector<value_type, C> BOOST_RV_REF_END other) { return static_cast<static_vector&>(base_t::operator= - (boost::move(static_cast<typename static_vector<value_type, C>::base_t&>(other)))); + (BOOST_MOVE_BASE(typename static_vector<value_type BOOST_MOVE_I C>::base_t, other))); } #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED @@ -383,8 +389,8 @@ public: //! @param other The static_vector which content will be swapped with this one's content. //! //! @par Throws - //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws, - //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws, + //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws, + //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws, //! //! @par Complexity //! Linear O(N). @@ -397,8 +403,8 @@ public: //! @param other The static_vector which content will be swapped with this one's content. //! //! @par Throws - //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws, - //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws, + //! @li If \c has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws, + //! @li If \c has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws, //! //! @par Complexity //! Linear O(N). @@ -462,7 +468,7 @@ public: //! //! @par Complexity //! Linear O(N). - void reserve(size_type count) BOOST_CONTAINER_NOEXCEPT; + void reserve(size_type count) BOOST_NOEXCEPT_OR_NOTHROW; //! @pre <tt>size() < capacity()</tt> //! @@ -703,7 +709,7 @@ public: //! //! @par Complexity //! Constant O(1). - void clear() BOOST_CONTAINER_NOEXCEPT; + void clear() BOOST_NOEXCEPT_OR_NOTHROW; //! @pre <tt>i < size()</tt> //! @@ -769,6 +775,66 @@ public: //! Constant O(1). const_reference operator[](size_type i) const; + //! @pre <tt>i =< size()</tt> + //! + //! @brief Returns a iterator to the i-th element. + //! + //! @param i The element's index. + //! + //! @return a iterator to the i-th element. + //! + //! @par Throws + //! Nothing by default. + //! + //! @par Complexity + //! Constant O(1). + iterator nth(size_type i); + + //! @pre <tt>i =< size()</tt> + //! + //! @brief Returns a const_iterator to the i-th element. + //! + //! @param i The element's index. + //! + //! @return a const_iterator to the i-th element. + //! + //! @par Throws + //! Nothing by default. + //! + //! @par Complexity + //! Constant O(1). + const_iterator nth(size_type i) const; + + //! @pre <tt>begin() <= p <= end()</tt> + //! + //! @brief Returns the index of the element pointed by p. + //! + //! @param i The element's index. + //! + //! @return The index of the element pointed by p. + //! + //! @par Throws + //! Nothing by default. + //! + //! @par Complexity + //! Constant O(1). + size_type index_of(iterator p); + + //! @pre <tt>begin() <= p <= end()</tt> + //! + //! @brief Returns the index of the element pointed by p. + //! + //! @param i The index of the element pointed by p. + //! + //! @return a const_iterator to the i-th element. + //! + //! @par Throws + //! Nothing by default. + //! + //! @par Complexity + //! Constant O(1). + size_type index_of(const_iterator p) const; + //! @pre \c !empty() //! //! @brief Returns reference to the first element. @@ -833,7 +899,7 @@ public: //! //! @par Complexity //! Constant O(1). - Value * data() BOOST_CONTAINER_NOEXCEPT; + Value * data() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range. //! For a non-empty vector <tt>data() == &front()</tt>. @@ -843,7 +909,7 @@ public: //! //! @par Complexity //! Constant O(1). - const Value * data() const BOOST_CONTAINER_NOEXCEPT; + const Value * data() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns iterator to the first element. //! @@ -854,7 +920,7 @@ public: //! //! @par Complexity //! Constant O(1). - iterator begin() BOOST_CONTAINER_NOEXCEPT; + iterator begin() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const iterator to the first element. //! @@ -865,7 +931,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_iterator begin() const BOOST_CONTAINER_NOEXCEPT; + const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const iterator to the first element. //! @@ -876,7 +942,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT; + const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns iterator to the one after the last element. //! @@ -887,7 +953,7 @@ public: //! //! @par Complexity //! Constant O(1). - iterator end() BOOST_CONTAINER_NOEXCEPT; + iterator end() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const iterator to the one after the last element. //! @@ -898,7 +964,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_iterator end() const BOOST_CONTAINER_NOEXCEPT; + const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const iterator to the one after the last element. //! @@ -909,7 +975,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_iterator cend() const BOOST_CONTAINER_NOEXCEPT; + const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns reverse iterator to the first element of the reversed container. //! @@ -921,7 +987,7 @@ public: //! //! @par Complexity //! Constant O(1). - reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT; + reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const reverse iterator to the first element of the reversed container. //! @@ -933,7 +999,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT; + const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const reverse iterator to the first element of the reversed container. //! @@ -945,7 +1011,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT; + const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns reverse iterator to the one after the last element of the reversed container. //! @@ -957,7 +1023,7 @@ public: //! //! @par Complexity //! Constant O(1). - reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT; + reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const reverse iterator to the one after the last element of the reversed container. //! @@ -969,7 +1035,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT; + const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns const reverse iterator to the one after the last element of the reversed container. //! @@ -981,7 +1047,7 @@ public: //! //! @par Complexity //! Constant O(1). - const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT; + const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns container's capacity. //! @@ -992,7 +1058,7 @@ public: //! //! @par Complexity //! Constant O(1). - static size_type capacity() BOOST_CONTAINER_NOEXCEPT; + static size_type capacity() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns container's capacity. //! @@ -1003,7 +1069,7 @@ public: //! //! @par Complexity //! Constant O(1). - static size_type max_size() BOOST_CONTAINER_NOEXCEPT; + static size_type max_size() BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Returns the number of stored elements. //! @@ -1014,7 +1080,7 @@ public: //! //! @par Complexity //! Constant O(1). - size_type size() const BOOST_CONTAINER_NOEXCEPT; + size_type size() const BOOST_NOEXCEPT_OR_NOTHROW; //! @brief Queries if the container contains elements. //! @@ -1026,7 +1092,7 @@ public: //! //! @par Complexity //! Constant O(1). - bool empty() const BOOST_CONTAINER_NOEXCEPT; + bool empty() const BOOST_NOEXCEPT_OR_NOTHROW; #else friend void swap(static_vector &x, static_vector &y) |