Chris@16: // Boost.Container varray Chris@16: // Chris@101: // Copyright (c) 2012-2015 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_GEOMETRY_INDEX_DETAIL_VARRAY_HPP Chris@16: #define BOOST_GEOMETRY_INDEX_DETAIL_VARRAY_HPP Chris@16: Chris@16: // TODO - REMOVE/CHANGE Chris@16: #include Chris@16: #include Chris@101: Chris@101: #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@101: #include Chris@101: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // TODO - use std::reverse_iterator and std::iterator_traits Chris@16: // instead Boost.Iterator to remove dependency? Chris@16: // or boost/detail/iterator.hpp ? Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@101: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: /*! Chris@16: \defgroup varray_non_member varray non-member functions Chris@16: */ Chris@16: Chris@16: namespace boost { namespace geometry { namespace index { namespace detail { Chris@16: Chris@16: namespace varray_detail { Chris@16: Chris@16: template Chris@16: struct varray_traits Chris@16: { Chris@16: typedef Value value_type; Chris@16: typedef std::size_t size_type; Chris@16: typedef std::ptrdiff_t difference_type; Chris@16: typedef Value * pointer; Chris@16: typedef const Value * const_pointer; Chris@16: typedef Value & reference; Chris@16: typedef const Value & const_reference; Chris@16: Chris@16: typedef boost::false_type use_memop_in_swap_and_move; Chris@16: typedef boost::false_type use_optimized_swap; Chris@16: typedef boost::false_type disable_trivial_init; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct checker Chris@16: { Chris@16: typedef typename Varray::size_type size_type; Chris@16: typedef typename Varray::const_iterator const_iterator; Chris@16: Chris@16: static inline void check_capacity(Varray const& v, size_type s) Chris@16: { Chris@16: BOOST_GEOMETRY_INDEX_ASSERT(s <= v.capacity(), "size too big"); Chris@16: Chris@16: ::boost::ignore_unused_variable_warning(v); Chris@16: ::boost::ignore_unused_variable_warning(s); Chris@16: } Chris@16: Chris@16: static inline void throw_out_of_bounds(Varray const& v, size_type i) Chris@16: { Chris@16: if ( v.size() <= i ) Chris@101: throw_out_of_range("index out of bounds"); Chris@16: Chris@16: ::boost::ignore_unused_variable_warning(v); Chris@16: ::boost::ignore_unused_variable_warning(i); Chris@16: } Chris@16: Chris@16: static inline void check_index(Varray const& v, size_type i) Chris@16: { Chris@16: BOOST_GEOMETRY_INDEX_ASSERT(i < v.size(), "index out of bounds"); Chris@16: Chris@16: ::boost::ignore_unused_variable_warning(v); Chris@16: ::boost::ignore_unused_variable_warning(i); Chris@16: } Chris@16: Chris@16: static inline void check_not_empty(Varray const& v) Chris@16: { Chris@16: BOOST_GEOMETRY_INDEX_ASSERT(!v.empty(), "the container is empty"); Chris@16: Chris@16: ::boost::ignore_unused_variable_warning(v); Chris@16: } Chris@16: Chris@16: static inline void check_iterator_end_neq(Varray const& v, const_iterator position) Chris@16: { Chris@16: BOOST_GEOMETRY_INDEX_ASSERT(v.begin() <= position && position < v.end(), "iterator out of bounds"); Chris@16: Chris@16: ::boost::ignore_unused_variable_warning(v); Chris@16: ::boost::ignore_unused_variable_warning(position); Chris@16: } Chris@16: Chris@16: static inline void check_iterator_end_eq(Varray const& v, const_iterator position) Chris@16: { Chris@16: BOOST_GEOMETRY_INDEX_ASSERT(v.begin() <= position && position <= v.end(), "iterator out of bounds"); Chris@16: Chris@16: ::boost::ignore_unused_variable_warning(v); Chris@16: ::boost::ignore_unused_variable_warning(position); Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace varray_detail Chris@16: Chris@16: /*! Chris@16: \brief A variable-size array container with fixed capacity. Chris@16: Chris@16: varray 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 varray 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 varray 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 varray unlike C arrays or std::array which must construct Chris@16: all elements on instantiation. The behavior of varray 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 and out of bounds errors result in undefined behavior unless Chris@16: otherwise specified. In this respect if size() == capacity(), then varray::push_back() Chris@16: behaves like std::vector pop_front() if size() == empty(). The reason for this difference Chris@16: is because unlike vectors, varray does not perform allocation. Chris@16: Chris@16: \par Advanced Usage Chris@16: Error handling behavior can be modified to more closely match std::vector exception behavior Chris@16: when exceeding bounds by providing an alternate Strategy and varray_traits instantiation. Chris@16: Chris@16: \tparam Value The type of element that will be stored. Chris@16: \tparam Capacity The maximum number of elements varray can store, fixed at compile time. Chris@16: \tparam Strategy Defines the public typedefs and error handlers, Chris@16: implements StaticVectorStrategy and has some similarities Chris@16: to an Allocator. Chris@16: */ Chris@16: template Chris@16: class varray Chris@16: { Chris@16: typedef varray_detail::varray_traits vt; Chris@16: typedef varray_detail::checker errh; Chris@16: Chris@16: BOOST_MPL_ASSERT_MSG( Chris@16: ( boost::is_unsigned::value && Chris@16: sizeof(typename boost::uint_value_t::least) <= sizeof(typename vt::size_type) ), Chris@16: SIZE_TYPE_IS_TOO_SMALL_FOR_SPECIFIED_CAPACITY, Chris@16: (varray) Chris@16: ); Chris@16: Chris@16: typedef boost::aligned_storage< Chris@16: sizeof(Value[Capacity]), Chris@16: boost::alignment_of::value Chris@16: > aligned_storage_type; Chris@16: Chris@16: template Chris@16: friend class varray; Chris@16: Chris@16: BOOST_COPYABLE_AND_MOVABLE(varray) Chris@16: Chris@101: #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES Chris@16: public: Chris@16: template Chris@16: varray & operator=(varray & sv) Chris@16: { Chris@16: typedef varray other; Chris@16: this->operator=(static_cast &>(const_cast(sv))); Chris@16: return *this; Chris@16: } Chris@16: #endif Chris@16: Chris@16: public: Chris@16: //! @brief The type of elements stored in the container. Chris@16: typedef typename vt::value_type value_type; Chris@16: //! @brief The unsigned integral type used by the container. Chris@16: typedef typename vt::size_type size_type; Chris@16: //! @brief The pointers difference type. Chris@16: typedef typename vt::difference_type difference_type; Chris@16: //! @brief The pointer type. Chris@16: typedef typename vt::pointer pointer; Chris@16: //! @brief The const pointer type. Chris@16: typedef typename vt::const_pointer const_pointer; Chris@16: //! @brief The value reference type. Chris@16: typedef typename vt::reference reference; Chris@16: //! @brief The value const reference type. Chris@16: typedef typename vt::const_reference const_reference; Chris@16: Chris@16: //! @brief The iterator type. Chris@16: typedef pointer iterator; Chris@16: //! @brief The const iterator type. Chris@16: typedef const_pointer const_iterator; Chris@16: //! @brief The reverse iterator type. Chris@16: typedef boost::reverse_iterator reverse_iterator; Chris@16: //! @brief The const reverse iterator. Chris@16: typedef boost::reverse_iterator const_reverse_iterator; Chris@16: Chris@16: //! @brief Constructs an empty varray. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! Nothing. Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: varray() Chris@16: : m_size(0) Chris@16: {} Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Constructs a varray containing count default constructed 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: explicit varray(size_type count) Chris@16: : m_size(0) Chris@16: { Chris@16: this->resize(count); // may throw Chris@16: } Chris@16: Chris@16: //! @pre count <= capacity() Chris@16: //! Chris@16: //! @brief Constructs a varray 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: varray(size_type count, value_type const& value) Chris@16: : m_size(0) Chris@16: { Chris@16: this->resize(count, value); // may throw 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 varray 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: varray(Iterator first, Iterator last) Chris@16: : m_size(0) Chris@16: { Chris@16: BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal)); // Make sure you passed a ForwardIterator Chris@16: Chris@16: this->assign(first, last); // may throw Chris@16: } Chris@16: Chris@16: //! @brief Constructs a copy of other varray. Chris@16: //! Chris@16: //! @param other The varray 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: varray(varray const& other) Chris@16: : m_size(other.size()) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: sv::uninitialized_copy(other.begin(), other.end(), this->begin()); // may throw Chris@16: } Chris@16: Chris@16: //! @pre other.size() <= capacity(). Chris@16: //! Chris@16: //! @brief Constructs a copy of other varray. Chris@16: //! Chris@16: //! @param other The varray which content will be copied to this one. Chris@16: //! Chris@16: //! @par Throws Chris@16: //! If Value's copy constructor throws. Chris@16: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: varray(varray const& other) Chris@16: : m_size(other.size()) Chris@16: { Chris@16: errh::check_capacity(*this, other.size()); // may throw Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: sv::uninitialized_copy(other.begin(), other.end(), this->begin()); // may throw Chris@16: } Chris@16: Chris@16: //! @brief Copy assigns Values stored in the other varray to this one. Chris@16: //! Chris@16: //! @param other The varray 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: varray & operator=(BOOST_COPY_ASSIGN_REF(varray) other) Chris@16: { Chris@16: this->assign(other.begin(), other.end()); // may throw Chris@16: 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 varray to this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@101: varray & operator=(BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(varray, value_type, C) other) Chris@16: { Chris@16: this->assign(other.begin(), other.end()); // may throw Chris@16: Chris@16: return *this; Chris@16: } Chris@16: Chris@16: //! @brief Move constructor. Moves Values stored in the other varray to this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li It throws only if \c use_memop_in_swap_and_move is \c false_type - default. Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: varray(BOOST_RV_REF(varray) other) Chris@16: { Chris@16: typedef typename Chris@16: vt::use_memop_in_swap_and_move use_memop_in_swap_and_move; Chris@16: Chris@16: this->move_ctor_dispatch(other, use_memop_in_swap_and_move()); Chris@16: } Chris@16: Chris@16: //! @pre other.size() <= capacity() Chris@16: //! Chris@16: //! @brief Move constructor. Moves Values stored in the other varray to this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li It throws only if \c use_memop_in_swap_and_move is false_type - default. Chris@16: //! @endinternal Chris@16: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: varray(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other) Chris@16: : m_size(other.m_size) Chris@16: { Chris@16: errh::check_capacity(*this, other.size()); // may throw Chris@16: Chris@16: typedef typename Chris@16: vt::use_memop_in_swap_and_move use_memop_in_swap_and_move; Chris@16: Chris@16: this->move_ctor_dispatch(other, use_memop_in_swap_and_move()); Chris@16: } Chris@16: Chris@16: //! @brief Move assignment. Moves Values stored in the other varray to this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li It throws only if \c use_memop_in_swap_and_move is \c false_type - default. Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: varray & operator=(BOOST_RV_REF(varray) other) Chris@16: { Chris@16: if ( &other == this ) Chris@16: return *this; Chris@16: Chris@16: typedef typename Chris@16: vt::use_memop_in_swap_and_move use_memop_in_swap_and_move; Chris@16: Chris@16: this->move_assign_dispatch(other, use_memop_in_swap_and_move()); Chris@16: 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 varray to this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li It throws only if \c use_memop_in_swap_and_move is \c false_type - default. Chris@16: //! @endinternal Chris@16: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: varray & operator=(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other) Chris@16: { Chris@16: errh::check_capacity(*this, other.size()); // may throw Chris@16: Chris@16: typedef typename Chris@16: vt::use_memop_in_swap_and_move use_memop_in_swap_and_move; Chris@16: Chris@16: this->move_assign_dispatch(other, use_memop_in_swap_and_move()); Chris@16: Chris@16: return *this; Chris@16: } 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: ~varray() Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: sv::destroy(this->begin(), this->end()); Chris@16: } Chris@16: Chris@16: //! @brief Swaps contents of the other varray and this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li It throws only if \c use_memop_in_swap_and_move and \c use_optimized_swap are \c false_type - default. Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void swap(varray & other) Chris@16: { Chris@16: typedef typename Chris@16: vt::use_optimized_swap use_optimized_swap; Chris@16: Chris@16: this->swap_dispatch(other, use_optimized_swap()); Chris@16: } Chris@16: Chris@16: //! @pre other.size() <= capacity() && size() <= other.capacity() Chris@16: //! Chris@16: //! @brief Swaps contents of the other varray and this one. Chris@16: //! Chris@16: //! @param other The varray 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: //! @internal Chris@16: //! @li It throws only if \c use_memop_in_swap_and_move and \c use_optimized_swap are \c false_type - default. Chris@16: //! @endinternal Chris@16: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: template Chris@16: void swap(varray & other) Chris@16: { Chris@16: errh::check_capacity(*this, other.size()); Chris@16: errh::check_capacity(other, this->size()); Chris@16: Chris@16: typedef typename Chris@16: vt::use_optimized_swap use_optimized_swap; Chris@16: Chris@16: this->swap_dispatch(other, use_optimized_swap()); Chris@16: } 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 constructed. 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void resize(size_type count) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: typedef typename vt::disable_trivial_init dti; Chris@16: Chris@16: if ( count < m_size ) Chris@16: { Chris@16: sv::destroy(this->begin() + count, this->end()); Chris@16: } Chris@16: else Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: Chris@16: sv::uninitialized_fill(this->end(), this->begin() + count, dti()); // may throw Chris@16: } Chris@16: m_size = count; // update end Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal 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: if ( count < m_size ) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: sv::destroy(this->begin() + count, this->end()); Chris@16: } Chris@16: else Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: Chris@16: std::uninitialized_fill(this->end(), this->begin() + count, value); // may throw Chris@16: } Chris@16: m_size = count; // update end Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Linear O(N). Chris@16: void reserve(size_type count) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: void push_back(value_type const& value) Chris@16: { Chris@16: typedef typename vt::disable_trivial_init dti; Chris@16: Chris@16: errh::check_capacity(*this, m_size + 1); // may throw Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: sv::construct(dti(), this->end(), value); // may throw Chris@16: ++m_size; // update end Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal 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: typedef typename vt::disable_trivial_init dti; Chris@16: Chris@16: errh::check_capacity(*this, m_size + 1); // may throw Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: sv::construct(dti(), this->end(), ::boost::move(value)); // may throw Chris@16: ++m_size; // update end Chris@16: } 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: errh::check_not_empty(*this); Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: sv::destroy(this->end() - 1); Chris@16: --m_size; // update end Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal 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: typedef typename vt::disable_trivial_init dti; Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: errh::check_capacity(*this, m_size + 1); // may throw Chris@16: Chris@16: if ( position == this->end() ) Chris@16: { Chris@16: sv::construct(dti(), position, value); // may throw Chris@16: ++m_size; // update end Chris@16: } Chris@16: else Chris@16: { Chris@16: // TODO - should move be used only if it's nonthrowing? Chris@16: value_type & r = *(this->end() - 1); Chris@16: sv::construct(dti(), this->end(), boost::move(r)); // may throw Chris@16: ++m_size; // update end Chris@16: sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw Chris@16: sv::assign(position, value); // may throw Chris@16: } Chris@16: Chris@16: return position; Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal 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: typedef typename vt::disable_trivial_init dti; Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: errh::check_capacity(*this, m_size + 1); // may throw Chris@16: Chris@16: if ( position == this->end() ) Chris@16: { Chris@16: sv::construct(dti(), position, boost::move(value)); // may throw Chris@16: ++m_size; // update end Chris@16: } Chris@16: else Chris@16: { Chris@16: // TODO - should move be used only if it's nonthrowing? Chris@16: value_type & r = *(this->end() - 1); Chris@16: sv::construct(dti(), this->end(), boost::move(r)); // may throw Chris@16: ++m_size; // update end Chris@16: sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw Chris@16: sv::assign(position, boost::move(value)); // may throw Chris@16: } Chris@16: Chris@16: return position; Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal 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: errh::check_iterator_end_eq(*this, position); Chris@16: errh::check_capacity(*this, m_size + count); // may throw Chris@16: Chris@16: if ( position == this->end() ) Chris@16: { Chris@16: std::uninitialized_fill(position, position + count, value); // may throw Chris@16: m_size += count; // update end Chris@16: } Chris@16: else Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: difference_type to_move = std::distance(position, this->end()); Chris@16: Chris@16: // TODO - should following lines check for exception and revert to the old size? Chris@16: Chris@16: if ( count < static_cast(to_move) ) Chris@16: { Chris@16: sv::uninitialized_move(this->end() - count, this->end(), this->end()); // may throw Chris@16: m_size += count; // update end Chris@16: sv::move_backward(position, position + to_move - count, this->end() - count); // may throw Chris@16: std::fill_n(position, count, value); // may throw Chris@16: } Chris@16: else Chris@16: { Chris@16: std::uninitialized_fill(this->end(), position + count, value); // may throw Chris@16: m_size += count - to_move; // update end Chris@16: sv::uninitialized_move(position, position + to_move, position + count); // may throw Chris@16: m_size += to_move; // update end Chris@16: std::fill_n(position, to_move, value); // may throw Chris@16: } Chris@16: } Chris@16: Chris@16: return position; Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal 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: BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal)); // Make sure you passed a ForwardIterator Chris@16: Chris@16: typedef typename boost::iterator_traversal::type traversal; Chris@16: this->insert_dispatch(position, first, last, traversal()); Chris@16: Chris@16: return position; Chris@16: } 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: namespace sv = varray_detail; Chris@16: Chris@16: errh::check_iterator_end_neq(*this, position); Chris@16: Chris@16: //TODO - add empty check? Chris@16: //errh::check_empty(*this); Chris@16: Chris@16: sv::move(position + 1, this->end(), position); // may throw Chris@16: sv::destroy(this->end() - 1); Chris@16: --m_size; Chris@16: Chris@16: return position; Chris@16: } 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: namespace sv = varray_detail; Chris@16: Chris@16: errh::check_iterator_end_eq(*this, first); Chris@16: errh::check_iterator_end_eq(*this, last); Chris@16: Chris@16: difference_type n = std::distance(first, last); Chris@16: Chris@16: //TODO - add invalid range check? Chris@101: //BOOST_GEOMETRY_INDEX_ASSERT(0 <= n, "invalid range"); Chris@16: //TODO - add this->size() check? Chris@101: //BOOST_GEOMETRY_INDEX_ASSERT(n <= this->size(), "invalid range"); Chris@16: Chris@16: sv::move(last, this->end(), first); // may throw Chris@16: sv::destroy(this->end() - n, this->end()); Chris@16: m_size -= n; Chris@16: Chris@16: return first; Chris@16: } 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: BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal)); // Make sure you passed a ForwardIterator Chris@16: Chris@16: typedef typename boost::iterator_traversal::type traversal; Chris@16: this->assign_dispatch(first, last, traversal()); // may throw Chris@16: } 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: if ( count < m_size ) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: std::fill_n(this->begin(), count, value); // may throw Chris@16: sv::destroy(this->begin() + count, this->end()); Chris@16: } Chris@16: else Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: Chris@16: std::fill_n(this->begin(), m_size, value); // may throw Chris@16: std::uninitialized_fill(this->end(), this->begin() + count, value); // may throw Chris@16: } Chris@16: m_size = count; // update end Chris@16: } Chris@16: Chris@16: #if !defined(BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE) Chris@101: #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant O(1). Chris@16: template Chris@16: void emplace_back(BOOST_FWD_REF(Args) ...args) Chris@16: { Chris@16: typedef typename vt::disable_trivial_init dti; Chris@16: Chris@16: errh::check_capacity(*this, m_size + 1); // may throw Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: sv::construct(dti(), this->end(), ::boost::forward(args)...); // may throw Chris@16: ++m_size; // update end Chris@16: } 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: //! @internal Chris@16: //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default). Chris@16: //! @endinternal Chris@16: //! Chris@16: //! @par Complexity Chris@16: //! Constant or linear. Chris@16: template Chris@16: iterator emplace(iterator position, BOOST_FWD_REF(Args) ...args) Chris@16: { Chris@16: typedef typename vt::disable_trivial_init dti; Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: errh::check_capacity(*this, m_size + 1); // may throw Chris@16: Chris@16: if ( position == this->end() ) Chris@16: { Chris@16: sv::construct(dti(), position, ::boost::forward(args)...); // may throw Chris@16: ++m_size; // update end Chris@16: } Chris@16: else Chris@16: { Chris@16: // TODO - should following lines check for exception and revert to the old size? Chris@16: Chris@16: // TODO - should move be used only if it's nonthrowing? Chris@16: value_type & r = *(this->end() - 1); Chris@16: sv::construct(dti(), this->end(), boost::move(r)); // may throw Chris@16: ++m_size; // update end Chris@16: sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw Chris@16: Chris@16: aligned_storage::value> temp_storage; Chris@16: value_type * val_p = static_cast(temp_storage.address()); Chris@16: sv::construct(dti(), val_p, ::boost::forward(args)...); // may throw Chris@16: sv::scoped_destructor d(val_p); Chris@16: sv::assign(position, ::boost::move(*val_p)); // may throw Chris@16: } Chris@16: Chris@16: return position; Chris@16: } Chris@16: Chris@101: #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) Chris@16: Chris@101: #define BOOST_GEOMETRY_INDEX_DETAIL_VARRAY_EMPLACE(N) \ Chris@101: BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ Chris@101: void emplace_back(BOOST_MOVE_UREF##N) \ Chris@16: { \ Chris@16: typedef typename vt::disable_trivial_init dti; \ Chris@16: \ Chris@16: errh::check_capacity(*this, m_size + 1); /*may throw*/\ Chris@16: \ Chris@101: namespace sv = varray_detail; \ Chris@101: sv::construct(dti(), this->end() BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ Chris@16: ++m_size; /*update end*/ \ Chris@16: } \ Chris@101: \ Chris@101: BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ Chris@101: iterator emplace(iterator position BOOST_MOVE_I##N BOOST_MOVE_UREF##N) \ Chris@16: { \ Chris@16: typedef typename vt::disable_trivial_init dti; \ Chris@16: namespace sv = varray_detail; \ Chris@16: \ Chris@16: errh::check_iterator_end_eq(*this, position); \ Chris@16: errh::check_capacity(*this, m_size + 1); /*may throw*/\ Chris@16: \ Chris@16: if ( position == this->end() ) \ Chris@16: { \ Chris@101: sv::construct(dti(), position BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ Chris@16: ++m_size; /*update end*/ \ Chris@16: } \ Chris@16: else \ Chris@16: { \ Chris@16: /* TODO - should following lines check for exception and revert to the old size? */ \ Chris@16: /* TODO - should move be used only if it's nonthrowing? */ \ Chris@16: \ Chris@16: value_type & r = *(this->end() - 1); \ Chris@101: sv::construct(dti(), this->end(), boost::move(r)); /*may throw*/\ Chris@16: ++m_size; /*update end*/ \ Chris@16: sv::move_backward(position, this->end() - 2, this->end() - 1); /*may throw*/\ Chris@16: \ Chris@16: aligned_storage::value> temp_storage; \ Chris@16: value_type * val_p = static_cast(temp_storage.address()); \ Chris@101: sv::construct(dti(), val_p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ Chris@16: sv::scoped_destructor d(val_p); \ Chris@16: sv::assign(position, ::boost::move(*val_p)); /*may throw*/\ Chris@16: } \ Chris@16: \ Chris@16: return position; \ Chris@16: } \ Chris@101: Chris@101: BOOST_MOVE_ITERATE_0TO9(BOOST_GEOMETRY_INDEX_DETAIL_VARRAY_EMPLACE) Chris@101: #undef BOOST_GEOMETRY_INDEX_DETAIL_VARRAY_EMPLACE Chris@16: Chris@101: #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) Chris@16: #endif // !BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE 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() Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: sv::destroy(this->begin(), this->end()); Chris@16: m_size = 0; // update end Chris@16: } 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: errh::throw_out_of_bounds(*this, i); // may throw Chris@16: return *(this->begin() + i); Chris@16: } 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: errh::throw_out_of_bounds(*this, i); // may throw Chris@16: return *(this->begin() + i); Chris@16: } 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: // TODO: Remove bounds check? std::vector and std::array operator[] don't check. Chris@16: errh::check_index(*this, i); Chris@16: return *(this->begin() + i); Chris@16: } 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: errh::check_index(*this, i); Chris@16: return *(this->begin() + i); Chris@16: } 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: errh::check_not_empty(*this); Chris@16: return *(this->begin()); Chris@16: } 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: errh::check_not_empty(*this); Chris@16: return *(this->begin()); Chris@16: } 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: errh::check_not_empty(*this); Chris@16: return *(this->end() - 1); Chris@16: } 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: errh::check_not_empty(*this); Chris@16: return *(this->end() - 1); Chris@16: } 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() Chris@16: { Chris@16: return boost::addressof(*(this->ptr())); Chris@16: } 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 Chris@16: { Chris@16: return boost::addressof(*(this->ptr())); Chris@16: } Chris@16: 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() { return this->ptr(); } 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 { return this->ptr(); } 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 { return this->ptr(); } 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() { return this->begin() + m_size; } 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 { return this->begin() + m_size; } 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 { return this->cbegin() + m_size; } 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 varray. 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() { return reverse_iterator(this->end()); } 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 varray. 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 { return const_reverse_iterator(this->end()); } 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 varray. 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 { return const_reverse_iterator(this->end()); } 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 varray. 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() { return reverse_iterator(this->begin()); } 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 varray. 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 { return const_reverse_iterator(this->begin()); } 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 varray. 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 { return const_reverse_iterator(this->begin()); } 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() { return Capacity; } 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() { return Capacity; } 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 { return m_size; } 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 { return 0 == m_size; } Chris@16: Chris@16: private: Chris@16: Chris@16: // @par Throws Chris@16: // Nothing. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void move_ctor_dispatch(varray & other, boost::true_type /*use_memop*/) Chris@16: { Chris@16: ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size); Chris@16: m_size = other.m_size; Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // @li If boost::has_nothrow_move::value is true and Value's move constructor throws Chris@16: // @li If boost::has_nothrow_move::value is false and Value's copy constructor throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void move_ctor_dispatch(varray & other, boost::false_type /*use_memop*/) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: sv::uninitialized_move_if_noexcept(other.begin(), other.end(), this->begin()); // may throw Chris@16: m_size = other.m_size; Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // Nothing. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void move_assign_dispatch(varray & other, boost::true_type /*use_memop*/) Chris@16: { Chris@16: this->clear(); Chris@16: Chris@16: ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size); Chris@16: std::swap(m_size, other.m_size); Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // @li If boost::has_nothrow_move::value is true and Value's move constructor or move assignment throws Chris@16: // @li If boost::has_nothrow_move::value is false and Value's copy constructor or move assignment throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void move_assign_dispatch(varray & other, boost::false_type /*use_memop*/) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: if ( m_size <= static_cast(other.size()) ) Chris@16: { Chris@16: sv::move_if_noexcept(other.begin(), other.begin() + m_size, this->begin()); // may throw Chris@16: // TODO - perform uninitialized_copy first? Chris@16: sv::uninitialized_move_if_noexcept(other.begin() + m_size, other.end(), this->end()); // may throw Chris@16: } Chris@16: else Chris@16: { Chris@16: sv::move_if_noexcept(other.begin(), other.end(), this->begin()); // may throw Chris@16: sv::destroy(this->begin() + other.size(), this->end()); Chris@16: } Chris@16: m_size = other.size(); // update end Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // Nothing. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void swap_dispatch(varray & other, boost::true_type const& /*use_optimized_swap*/) Chris@16: { Chris@16: typedef typename Chris@16: boost::mpl::if_c< Chris@16: Capacity < C, Chris@16: aligned_storage_type, Chris@16: typename varray::aligned_storage_type Chris@16: >::type Chris@16: storage_type; Chris@16: Chris@16: storage_type temp; Chris@16: Value * temp_ptr = reinterpret_cast(temp.address()); Chris@16: Chris@16: ::memcpy(temp_ptr, this->data(), sizeof(Value) * this->size()); Chris@16: ::memcpy(this->data(), other.data(), sizeof(Value) * other.size()); Chris@16: ::memcpy(other.data(), temp_ptr, sizeof(Value) * this->size()); Chris@16: Chris@16: std::swap(m_size, other.m_size); Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // If Value's move constructor or move assignment throws Chris@16: // but only if use_memop_in_swap_and_move is false_type - default. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void swap_dispatch(varray & other, boost::false_type const& /*use_optimized_swap*/) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: typedef typename Chris@16: vt::use_memop_in_swap_and_move use_memop_in_swap_and_move; Chris@16: Chris@16: if ( this->size() < other.size() ) Chris@16: swap_dispatch_impl(this->begin(), this->end(), other.begin(), other.end(), use_memop_in_swap_and_move()); // may throw Chris@16: else Chris@16: swap_dispatch_impl(other.begin(), other.end(), this->begin(), this->end(), use_memop_in_swap_and_move()); // may throw Chris@16: std::swap(m_size, other.m_size); Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // Nothing. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, boost::true_type const& /*use_memop*/) Chris@16: { Chris@101: //BOOST_GEOMETRY_INDEX_ASSERT(std::distance(first_sm, last_sm) <= std::distance(first_la, last_la), Chris@101: // "incompatible ranges"); Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: for (; first_sm != last_sm ; ++first_sm, ++first_la) Chris@16: { Chris@16: boost::aligned_storage< Chris@16: sizeof(value_type), Chris@16: boost::alignment_of::value Chris@16: > temp_storage; Chris@16: value_type * temp_ptr = reinterpret_cast(temp_storage.address()); Chris@16: Chris@16: ::memcpy(temp_ptr, boost::addressof(*first_sm), sizeof(value_type)); Chris@16: ::memcpy(boost::addressof(*first_sm), boost::addressof(*first_la), sizeof(value_type)); Chris@16: ::memcpy(boost::addressof(*first_la), temp_ptr, sizeof(value_type)); Chris@16: } Chris@16: Chris@16: ::memcpy(first_sm, first_la, sizeof(value_type) * std::distance(first_la, last_la)); Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // If Value's move constructor or move assignment throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, boost::false_type const& /*use_memop*/) Chris@16: { Chris@101: //BOOST_GEOMETRY_INDEX_ASSERT(std::distance(first_sm, last_sm) <= std::distance(first_la, last_la), Chris@101: // "incompatible ranges"); Chris@16: Chris@16: namespace sv = varray_detail; Chris@16: for (; first_sm != last_sm ; ++first_sm, ++first_la) Chris@16: { Chris@16: //boost::swap(*first_sm, *first_la); // may throw Chris@16: value_type temp(boost::move(*first_sm)); // may throw Chris@16: *first_sm = boost::move(*first_la); // may throw Chris@16: *first_la = boost::move(temp); // may throw Chris@16: } Chris@16: sv::uninitialized_move(first_la, last_la, first_sm); // may throw Chris@16: sv::destroy(first_la, last_la); Chris@16: } Chris@16: Chris@16: // insert Chris@16: Chris@16: // @par Throws Chris@16: // If Value's move constructor, move assignment throws Chris@16: // or if Value's copy constructor or copy assignment throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void insert_dispatch(iterator position, Iterator first, Iterator last, boost::random_access_traversal_tag const&) Chris@16: { Chris@16: BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal)); // Make sure you passed a RandomAccessIterator Chris@16: Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: Chris@16: typename boost::iterator_difference::type Chris@16: count = std::distance(first, last); Chris@16: Chris@16: errh::check_capacity(*this, m_size + count); // may throw Chris@16: Chris@16: if ( position == this->end() ) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: sv::uninitialized_copy(first, last, position); // may throw Chris@16: m_size += count; // update end Chris@16: } Chris@16: else Chris@16: { Chris@16: this->insert_in_the_middle(position, first, last, count); // may throw Chris@16: } Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // If Value's move constructor, move assignment throws Chris@16: // or if Value's copy constructor or copy assignment throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void insert_dispatch(iterator position, Iterator first, Iterator last, Traversal const& /*not_random_access*/) Chris@16: { Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: Chris@16: if ( position == this->end() ) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: std::ptrdiff_t d = std::distance(position, this->begin() + Capacity); Chris@16: std::size_t count = sv::uninitialized_copy_s(first, last, position, d); // may throw Chris@16: Chris@16: errh::check_capacity(*this, count <= static_cast(d) ? m_size + count : Capacity + 1); // may throw Chris@16: Chris@16: m_size += count; Chris@16: } Chris@16: else Chris@16: { Chris@16: typename boost::iterator_difference::type Chris@16: count = std::distance(first, last); Chris@16: Chris@16: errh::check_capacity(*this, m_size + count); // may throw Chris@16: Chris@16: this->insert_in_the_middle(position, first, last, count); // may throw Chris@16: } Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // If Value's move constructor, move assignment throws Chris@16: // or if Value's copy constructor or copy assignment throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void insert_in_the_middle(iterator position, Iterator first, Iterator last, difference_type count) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: difference_type to_move = std::distance(position, this->end()); Chris@16: Chris@16: // TODO - should following lines check for exception and revert to the old size? Chris@16: Chris@16: if ( count < to_move ) Chris@16: { Chris@16: sv::uninitialized_move(this->end() - count, this->end(), this->end()); // may throw Chris@16: m_size += count; // update end Chris@16: sv::move_backward(position, position + to_move - count, this->end() - count); // may throw Chris@16: sv::copy(first, last, position); // may throw Chris@16: } Chris@16: else Chris@16: { Chris@16: Iterator middle_iter = first; Chris@16: std::advance(middle_iter, to_move); Chris@16: Chris@16: sv::uninitialized_copy(middle_iter, last, this->end()); // may throw Chris@16: m_size += count - to_move; // update end Chris@16: sv::uninitialized_move(position, position + to_move, position + count); // may throw Chris@16: m_size += to_move; // update end Chris@16: sv::copy(first, middle_iter, position); // may throw Chris@16: } Chris@16: } Chris@16: Chris@16: // assign Chris@16: Chris@16: // @par Throws Chris@16: // If Value's constructor or assignment taking dereferenced Iterator throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void assign_dispatch(Iterator first, Iterator last, boost::random_access_traversal_tag const& /*not_random_access*/) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: typename boost::iterator_difference::type Chris@16: s = std::distance(first, last); Chris@16: Chris@16: errh::check_capacity(*this, s); // may throw Chris@16: Chris@16: if ( m_size <= static_cast(s) ) Chris@16: { Chris@16: sv::copy(first, first + m_size, this->begin()); // may throw Chris@16: // TODO - perform uninitialized_copy first? Chris@16: sv::uninitialized_copy(first + m_size, last, this->end()); // may throw Chris@16: } Chris@16: else Chris@16: { Chris@16: sv::copy(first, last, this->begin()); // may throw Chris@16: sv::destroy(this->begin() + s, this->end()); Chris@16: } Chris@16: m_size = s; // update end Chris@16: } Chris@16: Chris@16: // @par Throws Chris@16: // If Value's constructor or assignment taking dereferenced Iterator throws. Chris@16: // @par Complexity Chris@16: // Linear O(N). Chris@16: template Chris@16: void assign_dispatch(Iterator first, Iterator last, Traversal const& /*not_random_access*/) Chris@16: { Chris@16: namespace sv = varray_detail; Chris@16: Chris@16: size_type s = 0; Chris@16: iterator it = this->begin(); Chris@16: Chris@16: for ( ; it != this->end() && first != last ; ++it, ++first, ++s ) Chris@16: *it = *first; // may throw Chris@16: Chris@16: sv::destroy(it, this->end()); Chris@16: Chris@16: std::ptrdiff_t d = std::distance(it, this->begin() + Capacity); Chris@16: std::size_t count = sv::uninitialized_copy_s(first, last, it, d); // may throw Chris@16: s += count; Chris@16: Chris@16: errh::check_capacity(*this, count <= static_cast(d) ? s : Capacity + 1); // may throw Chris@16: Chris@16: m_size = s; // update end Chris@16: } Chris@16: Chris@16: pointer ptr() Chris@16: { Chris@16: return pointer(static_cast(m_storage.address())); Chris@16: } Chris@16: Chris@16: const_pointer ptr() const Chris@16: { Chris@16: return const_pointer(static_cast(m_storage.address())); Chris@16: } Chris@16: Chris@16: size_type m_size; Chris@16: aligned_storage_type m_storage; Chris@16: }; Chris@16: Chris@16: #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) Chris@16: Chris@16: template Chris@16: class varray Chris@16: { Chris@16: typedef varray_detail::varray_traits vt; Chris@16: typedef varray_detail::checker errh; Chris@16: Chris@16: public: Chris@16: typedef typename vt::value_type value_type; Chris@16: typedef typename vt::size_type size_type; Chris@16: typedef typename vt::difference_type difference_type; Chris@16: typedef typename vt::pointer pointer; Chris@16: typedef typename vt::const_pointer const_pointer; Chris@16: typedef typename vt::reference reference; Chris@16: typedef typename vt::const_reference const_reference; Chris@16: Chris@16: typedef pointer iterator; Chris@16: typedef const_pointer const_iterator; Chris@16: typedef boost::reverse_iterator reverse_iterator; Chris@16: typedef boost::reverse_iterator const_reverse_iterator; Chris@16: Chris@16: // nothrow Chris@16: varray() {} Chris@16: Chris@16: // strong Chris@16: explicit varray(size_type count) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: // strong Chris@16: varray(size_type count, value_type const&) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: // strong Chris@16: varray(varray const& /*other*/) Chris@16: { Chris@16: //errh::check_capacity(*this, count); Chris@16: } Chris@16: Chris@16: // strong Chris@16: template Chris@16: varray(varray const& other) Chris@16: { Chris@16: errh::check_capacity(*this, other.size()); // may throw Chris@16: } Chris@16: Chris@16: // strong Chris@16: template Chris@16: varray(Iterator first, Iterator last) Chris@16: { Chris@16: errh::check_capacity(*this, std::distance(first, last)); // may throw Chris@16: } Chris@16: Chris@16: // basic Chris@16: varray & operator=(varray const& /*other*/) Chris@16: { Chris@16: //errh::check_capacity(*this, other.size()); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: // basic Chris@16: template Chris@16: varray & operator=(varray const& other) Chris@16: { Chris@16: errh::check_capacity(*this, other.size()); // may throw Chris@16: return *this; Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: ~varray() {} Chris@16: Chris@16: // strong Chris@16: void resize(size_type count) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: // strong Chris@16: void resize(size_type count, value_type const&) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: Chris@16: // nothrow Chris@16: void reserve(size_type count) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: // strong Chris@16: void push_back(value_type const&) Chris@16: { Chris@16: errh::check_capacity(*this, 1); // may throw Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: void pop_back() Chris@16: { Chris@16: errh::check_not_empty(*this); Chris@16: } Chris@16: Chris@16: // basic Chris@16: void insert(iterator position, value_type const&) Chris@16: { Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: errh::check_capacity(*this, 1); // may throw Chris@16: } Chris@16: Chris@16: // basic Chris@16: void insert(iterator position, size_type count, value_type const&) Chris@16: { Chris@16: errh::check_iterator_end_eq(*this, position); Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: // basic Chris@16: template Chris@16: void insert(iterator, Iterator first, Iterator last) Chris@16: { Chris@16: // TODO - add MPL_ASSERT, check if Iterator is really an iterator Chris@16: errh::check_capacity(*this, std::distance(first, last)); // may throw Chris@16: } Chris@16: Chris@16: // basic Chris@16: void erase(iterator position) Chris@16: { Chris@16: errh::check_iterator_end_neq(*this, position); Chris@16: } Chris@16: Chris@16: // basic Chris@16: void erase(iterator first, iterator last) Chris@16: { Chris@16: errh::check_iterator_end_eq(*this, first); Chris@16: errh::check_iterator_end_eq(*this, last); Chris@16: Chris@101: //BOOST_GEOMETRY_INDEX_ASSERT(0 <= n, "invalid range"); Chris@16: } Chris@16: Chris@16: // basic Chris@16: template Chris@16: void assign(Iterator first, Iterator last) Chris@16: { Chris@16: // TODO - add MPL_ASSERT, check if Iterator is really an iterator Chris@16: errh::check_capacity(*this, std::distance(first, last)); // may throw Chris@16: } Chris@16: Chris@16: // basic Chris@16: void assign(size_type count, value_type const&) Chris@16: { Chris@16: errh::check_capacity(*this, count); // may throw Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: void clear() {} Chris@16: Chris@16: // strong Chris@16: reference at(size_type i) Chris@16: { Chris@16: errh::throw_out_of_bounds(*this, i); // may throw Chris@16: return *(this->begin() + i); Chris@16: } Chris@16: Chris@16: // strong Chris@16: const_reference at(size_type i) const Chris@16: { Chris@16: errh::throw_out_of_bounds(*this, i); // may throw Chris@16: return *(this->begin() + i); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: reference operator[](size_type i) Chris@16: { Chris@16: errh::check_index(*this, i); Chris@16: return *(this->begin() + i); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: const_reference operator[](size_type i) const Chris@16: { Chris@16: errh::check_index(*this, i); Chris@16: return *(this->begin() + i); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: reference front() Chris@16: { Chris@16: errh::check_not_empty(*this); Chris@16: return *(this->begin()); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: const_reference front() const Chris@16: { Chris@16: errh::check_not_empty(*this); Chris@16: return *(this->begin()); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: reference back() Chris@16: { Chris@16: errh::check_not_empty(*this); Chris@16: return *(this->end() - 1); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: const_reference back() const Chris@16: { Chris@16: errh::check_not_empty(*this); Chris@16: return *(this->end() - 1); Chris@16: } Chris@16: Chris@16: // nothrow Chris@16: Value * data() { return boost::addressof(*(this->ptr())); } Chris@16: const Value * data() const { return boost::addressof(*(this->ptr())); } Chris@16: Chris@16: // nothrow Chris@16: iterator begin() { return this->ptr(); } Chris@16: const_iterator begin() const { return this->ptr(); } Chris@16: const_iterator cbegin() const { return this->ptr(); } Chris@16: iterator end() { return this->begin(); } Chris@16: const_iterator end() const { return this->begin(); } Chris@16: const_iterator cend() const { return this->cbegin(); } Chris@16: // nothrow Chris@16: reverse_iterator rbegin() { return reverse_iterator(this->end()); } Chris@16: const_reverse_iterator rbegin() const { return reverse_iterator(this->end()); } Chris@16: const_reverse_iterator crbegin() const { return reverse_iterator(this->end()); } Chris@16: reverse_iterator rend() { return reverse_iterator(this->begin()); } Chris@16: const_reverse_iterator rend() const { return reverse_iterator(this->begin()); } Chris@16: const_reverse_iterator crend() const { return reverse_iterator(this->begin()); } Chris@16: Chris@16: // nothrow Chris@16: size_type capacity() const { return 0; } Chris@16: size_type max_size() const { return 0; } Chris@16: size_type size() const { return 0; } Chris@16: bool empty() const { return true; } Chris@16: Chris@16: private: Chris@16: pointer ptr() Chris@16: { Chris@16: return pointer(reinterpret_cast(this)); Chris@16: } Chris@16: Chris@16: const_pointer ptr() const Chris@16: { Chris@16: return const_pointer(reinterpret_cast(this)); Chris@16: } Chris@16: }; Chris@16: Chris@16: #endif // !BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: //! @brief Checks if contents of two varrays are equal. Chris@16: //! Chris@16: //! @ingroup varray_non_member Chris@16: //! Chris@16: //! @param x The first varray. Chris@16: //! @param y The second varray. 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== (varray const& x, varray const& y) Chris@16: { Chris@16: return x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin()); Chris@16: } Chris@16: Chris@16: //! @brief Checks if contents of two varrays are not equal. Chris@16: //! Chris@16: //! @ingroup varray_non_member Chris@16: //! Chris@16: //! @param x The first varray. Chris@16: //! @param y The second varray. 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!= (varray const& x, varray const& y) Chris@16: { Chris@16: return !(x==y); Chris@16: } Chris@16: Chris@16: //! @brief Lexicographically compares varrays. Chris@16: //! Chris@16: //! @ingroup varray_non_member Chris@16: //! Chris@16: //! @param x The first varray. Chris@16: //! @param y The second varray. 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< (varray const& x, varray const& y) Chris@16: { Chris@16: return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); Chris@16: } Chris@16: Chris@16: //! @brief Lexicographically compares varrays. Chris@16: //! Chris@16: //! @ingroup varray_non_member Chris@16: //! Chris@16: //! @param x The first varray. Chris@16: //! @param y The second varray. 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> (varray const& x, varray const& y) Chris@16: { Chris@16: return y Chris@16: bool operator<= (varray const& x, varray const& y) Chris@16: { Chris@16: return !(y Chris@16: bool operator>= (varray const& x, varray const& y) Chris@16: { Chris@16: return !(x Chris@16: inline void swap(varray & x, varray & y) Chris@16: { Chris@16: x.swap(y); Chris@16: } Chris@16: Chris@16: }}}} // namespace boost::geometry::index::detail Chris@16: Chris@16: // TODO - REMOVE/CHANGE Chris@16: #include Chris@16: Chris@16: #endif // BOOST_GEOMETRY_INDEX_DETAIL_VARRAY_HPP