Mercurial > hg > vamp-build-and-test
diff DEPENDENCIES/generic/include/boost/container/list.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
line wrap: on
line diff
--- a/DEPENDENCIES/generic/include/boost/container/list.hpp Fri Sep 04 12:01:02 2015 +0100 +++ b/DEPENDENCIES/generic/include/boost/container/list.hpp Mon Sep 07 11:12:49 2015 +0100 @@ -1,53 +1,62 @@ ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // - +////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_LIST_HPP #define BOOST_CONTAINER_LIST_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> + +// container #include <boost/container/container_fwd.hpp> -#include <boost/container/detail/version_type.hpp> +#include <boost/container/new_allocator.hpp> //new_allocator +#include <boost/container/throw_exception.hpp> +// container/detail +#include <boost/container/detail/algorithm.hpp> +#include <boost/container/detail/compare_functors.hpp> +#include <boost/container/detail/iterator.hpp> #include <boost/container/detail/iterators.hpp> #include <boost/container/detail/mpl.hpp> -#include <boost/container/throw_exception.hpp> -#include <boost/move/utility.hpp> +#include <boost/container/detail/node_alloc_holder.hpp> +#include <boost/container/detail/version_type.hpp> +// move +#include <boost/move/utility_core.hpp> #include <boost/move/iterator.hpp> +#include <boost/move/traits.hpp> +// move/detail +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +# include <boost/move/detail/fwd_macros.hpp> +#endif #include <boost/move/detail/move_helpers.hpp> + +// intrusive #include <boost/intrusive/pointer_traits.hpp> -#include <boost/container/detail/utilities.hpp> -#include <boost/container/detail/algorithms.hpp> -#include <boost/type_traits/has_trivial_destructor.hpp> #include <boost/intrusive/list.hpp> +// other #include <boost/assert.hpp> -#include <boost/container/detail/node_alloc_holder.hpp> - -#if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) -#else -//Preprocessor library to emulate perfect forwarding -#include <boost/container/detail/preprocessor.hpp> +// std +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include <initializer_list> #endif -#include <iterator> -#include <utility> -#include <memory> -#include <functional> -#include <algorithm> - namespace boost { namespace container { -/// @cond +#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED namespace container_detail { template<class VoidPointer> @@ -77,6 +86,11 @@ { return this->m_data; } }; +template <class T, class VoidPointer> +struct iiterator_node_value_type< list_node<T,VoidPointer> > { + typedef T type; +}; + template<class Allocator> struct intrusive_list_type { @@ -99,7 +113,7 @@ }; } //namespace container_detail { -/// @endcond +#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED //! A list is a doubly linked list. That is, it is a Sequence that supports both //! forward and backward traversal, and (amortized) constant time insertion and @@ -111,8 +125,11 @@ //! after a list operation than it did before), but the iterators themselves will //! not be invalidated or made to point to different elements unless that invalidation //! or mutation is explicit. +//! +//! \tparam T The type of object that is stored in the list +//! \tparam Allocator The allocator used for all internal memory management #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED -template <class T, class Allocator = std::allocator<T> > +template <class T, class Allocator = new_allocator<T> > #else template <class T, class Allocator> #endif @@ -120,7 +137,7 @@ : protected container_detail::node_alloc_holder <Allocator, typename container_detail::intrusive_list_type<Allocator>::type> { - /// @cond + #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED typedef typename container_detail::intrusive_list_type<Allocator>::type Icont; typedef container_detail::node_alloc_holder<Allocator, Icont> AllocHolder; @@ -129,45 +146,15 @@ typedef typename AllocHolder::ValAlloc ValAlloc; typedef typename AllocHolder::Node Node; typedef container_detail::allocator_destroyer<NodeAlloc> Destroyer; - typedef typename AllocHolder::allocator_v1 allocator_v1; - typedef typename AllocHolder::allocator_v2 allocator_v2; typedef typename AllocHolder::alloc_version alloc_version; typedef boost::container::allocator_traits<Allocator> allocator_traits_type; - - class equal_to_value - { - typedef typename AllocHolder::value_type value_type; - const value_type &t_; - - public: - equal_to_value(const value_type &t) - : t_(t) - {} - - bool operator()(const value_type &t)const - { return t_ == t; } - }; - - template<class Pred> - struct ValueCompareToNodeCompare - : Pred - { - ValueCompareToNodeCompare(Pred pred) - : Pred(pred) - {} - - bool operator()(const Node &a, const Node &b) const - { return static_cast<const Pred&>(*this)(a.m_data, b.m_data); } - - bool operator()(const Node &a) const - { return static_cast<const Pred&>(*this)(a.m_data); } - }; + typedef boost::container::equal_to_value<Allocator> equal_to_value_type; BOOST_COPYABLE_AND_MOVABLE(list) - typedef container_detail::iterator<typename Icont::iterator, false> iterator_impl; - typedef container_detail::iterator<typename Icont::iterator, true> const_iterator_impl; - /// @endcond + typedef container_detail::iterator_from_iiterator<typename Icont::iterator, false> iterator_impl; + typedef container_detail::iterator_from_iiterator<typename Icont::iterator, true> const_iterator_impl; + #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED public: ////////////////////////////////////////////// @@ -187,8 +174,8 @@ typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type; typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; - typedef BOOST_CONTAINER_IMPDEF(std::reverse_iterator<iterator>) reverse_iterator; - typedef BOOST_CONTAINER_IMPDEF(std::reverse_iterator<const_iterator>) const_reverse_iterator; + typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<iterator>) reverse_iterator; + typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator; ////////////////////////////////////////////// // @@ -210,14 +197,14 @@ //! <b>Throws</b>: Nothing //! //! <b>Complexity</b>: Constant. - explicit list(const allocator_type &a) BOOST_CONTAINER_NOEXCEPT + explicit list(const allocator_type &a) BOOST_NOEXCEPT_OR_NOTHROW : AllocHolder(a) {} - //! <b>Effects</b>: Constructs a list that will use a copy of allocator a - //! and inserts n copies of value. + //! <b>Effects</b>: Constructs a list + //! and inserts n value-initialized value_types. //! - //! <b>Throws</b>: If allocator_type's default constructor or copy constructor + //! <b>Throws</b>: If allocator_type's default constructor //! throws or T's default or copy constructor throws. //! //! <b>Complexity</b>: Linear to n. @@ -228,7 +215,18 @@ //! <b>Effects</b>: Constructs a list that will use a copy of allocator a //! and inserts n copies of value. //! - //! <b>Throws</b>: If allocator_type's default constructor or copy constructor + //! <b>Throws</b>: If allocator_type's default constructor + //! throws or T's default or copy constructor throws. + //! + //! <b>Complexity</b>: Linear to n. + list(size_type n, const allocator_type &a) + : AllocHolder(a) + { this->resize(n); } + + //! <b>Effects</b>: Constructs a list that will use a copy of allocator a + //! and inserts n copies of value. + //! + //! <b>Throws</b>: If allocator_type's default constructor //! throws or T's default or copy constructor throws. //! //! <b>Complexity</b>: Linear to n. @@ -240,20 +238,20 @@ //! //! <b>Postcondition</b>: x == *this. //! - //! <b>Throws</b>: If allocator_type's default constructor or copy constructor throws. + //! <b>Throws</b>: If allocator_type's default constructor throws. //! //! <b>Complexity</b>: Linear to the elements x contains. list(const list& x) : AllocHolder(x) { this->insert(this->cbegin(), x.begin(), x.end()); } - //! <b>Effects</b>: Move constructor. Moves mx's resources to *this. + //! <b>Effects</b>: Move constructor. Moves x's resources to *this. //! //! <b>Throws</b>: If allocator_type's copy constructor throws. //! //! <b>Complexity</b>: Constant. list(BOOST_RV_REF(list) x) - : AllocHolder(boost::move(static_cast<AllocHolder&>(x))) + : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x)) {} //! <b>Effects</b>: Copy constructs a list using the specified allocator. @@ -268,7 +266,7 @@ { this->insert(this->cbegin(), x.begin(), x.end()); } //! <b>Effects</b>: Move constructor sing the specified allocator. - //! Moves mx's resources to *this. + //! Moves x's resources to *this. //! //! <b>Throws</b>: If allocation or value_type's copy constructor throws. //! @@ -280,15 +278,15 @@ this->icont().swap(x.icont()); } else{ - this->insert(this->cbegin(), x.begin(), x.end()); + this->insert(this->cbegin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); } } //! <b>Effects</b>: Constructs a list that will use a copy of allocator a //! and inserts a copy of the range [first, last) in the list. //! - //! <b>Throws</b>: If allocator_type's default constructor or copy constructor - //! throws or T's constructor taking an dereferenced InIt throws. + //! <b>Throws</b>: If allocator_type's default constructor + //! throws or T's constructor taking a dereferenced InIt throws. //! //! <b>Complexity</b>: Linear to the range [first, last). template <class InpIt> @@ -296,13 +294,28 @@ : AllocHolder(a) { this->insert(this->cbegin(), first, last); } + +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! <b>Effects</b>: Constructs a list that will use a copy of allocator a + //! and inserts a copy of the range [il.begin(), il.end()) in the list. + //! + //! <b>Throws</b>: If allocator_type's default constructor + //! throws or T's constructor taking a dereferenced + //! std::initializer_list iterator throws. + //! + //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()). + list(std::initializer_list<value_type> il, const Allocator &a = Allocator()) + : AllocHolder(a) + { this->insert(this->cbegin(), il.begin(), il.end()); } +#endif + //! <b>Effects</b>: Destroys the list. All stored values are destroyed //! and used memory is deallocated. //! //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Linear to the number of elements. - ~list() BOOST_CONTAINER_NOEXCEPT + ~list() BOOST_NOEXCEPT_OR_NOTHROW {} //AllocHolder clears the list //! <b>Effects</b>: Makes *this contain the same elements as x. @@ -329,36 +342,61 @@ return *this; } - //! <b>Effects</b>: Move assignment. All mx's values are transferred to *this. + //! <b>Effects</b>: Move assignment. All x's values are transferred to *this. //! //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had //! before the function. //! - //! <b>Throws</b>: If allocator_type's copy constructor throws. + //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment + //! is false and (allocation throws or value_type's move constructor throws) //! - //! <b>Complexity</b>: Constant. + //! <b>Complexity</b>: Constant if allocator_traits_type:: + //! propagate_on_container_move_assignment is true or + //! this->get>allocator() == x.get_allocator(). Linear otherwise. list& operator=(BOOST_RV_REF(list) x) + BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value + || allocator_traits_type::is_always_equal::value) { - if (&x != this){ - NodeAlloc &this_alloc = this->node_alloc(); - NodeAlloc &x_alloc = x.node_alloc(); - //If allocators are equal we can just swap pointers - if(this_alloc == x_alloc){ - //Destroy and swap pointers - this->clear(); - this->icont() = boost::move(x.icont()); - //Move allocator if needed - this->AllocHolder::move_assign_alloc(x); - } - //If unequal allocators, then do a one by one move - else{ - this->assign( boost::make_move_iterator(x.begin()) - , boost::make_move_iterator(x.end())); - } + BOOST_ASSERT(this != &x); + NodeAlloc &this_alloc = this->node_alloc(); + NodeAlloc &x_alloc = x.node_alloc(); + const bool propagate_alloc = allocator_traits_type:: + propagate_on_container_move_assignment::value; + const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal; + //Resources can be transferred if both allocators are + //going to be equal after this function (either propagated or already equal) + if(propagate_alloc || allocators_equal){ + //Destroy + this->clear(); + //Move allocator if needed + this->AllocHolder::move_assign_alloc(x); + //Obtain resources + this->icont() = boost::move(x.icont()); + } + //Else do a one by one move + else{ + this->assign( boost::make_move_iterator(x.begin()) + , boost::make_move_iterator(x.end())); } return *this; } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! <b>Effects</b>: Makes *this contain the same elements as il. + //! + //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy + //! of each of x's elements. + //! + //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. + //! + //! <b>Complexity</b>: Linear to the number of elements in x. + list& operator=(std::initializer_list<value_type> il) + { + assign(il.begin(), il.end()); + return *this; + } +#endif + //! <b>Effects</b>: Assigns the n copies of val to *this. //! //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. @@ -396,12 +434,23 @@ } } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this. + //! + //! <b>Throws</b>: If memory allocation throws or + //! T's constructor from dereferencing std::initializer_list iterator throws. + //! + //! <b>Complexity</b>: Linear to n. + void assign(std::initializer_list<value_type> il) + { assign(il.begin(), il.end()); } +#endif + //! <b>Effects</b>: Returns a copy of the internal allocator. //! //! <b>Throws</b>: If allocator's copy constructor throws. //! //! <b>Complexity</b>: Constant. - allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT + allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW { return allocator_type(this->node_alloc()); } //! <b>Effects</b>: Returns a reference to the internal allocator. @@ -411,7 +460,7 @@ //! <b>Complexity</b>: Constant. //! //! <b>Note</b>: Non-standard extension. - stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT + stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW { return this->node_alloc(); } //! <b>Effects</b>: Returns a reference to the internal allocator. @@ -421,7 +470,7 @@ //! <b>Complexity</b>: Constant. //! //! <b>Note</b>: Non-standard extension. - const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT + const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW { return this->node_alloc(); } ////////////////////////////////////////////// @@ -435,7 +484,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - iterator begin() BOOST_CONTAINER_NOEXCEPT + iterator begin() BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->icont().begin()); } //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. @@ -443,7 +492,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_iterator begin() const BOOST_CONTAINER_NOEXCEPT + const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW { return this->cbegin(); } //! <b>Effects</b>: Returns an iterator to the end of the list. @@ -451,7 +500,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - iterator end() BOOST_CONTAINER_NOEXCEPT + iterator end() BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->icont().end()); } //! <b>Effects</b>: Returns a const_iterator to the end of the list. @@ -459,7 +508,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_iterator end() const BOOST_CONTAINER_NOEXCEPT + const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW { return this->cend(); } //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning @@ -468,7 +517,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT + reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW { return reverse_iterator(end()); } //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning @@ -477,7 +526,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT + const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW { return this->crbegin(); } //! <b>Effects</b>: Returns a reverse_iterator pointing to the end @@ -486,7 +535,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT + reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW { return reverse_iterator(begin()); } //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end @@ -495,7 +544,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT + const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW { return this->crend(); } //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. @@ -503,7 +552,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT + const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW { return const_iterator(this->non_const_icont().begin()); } //! <b>Effects</b>: Returns a const_iterator to the end of the list. @@ -511,7 +560,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_iterator cend() const BOOST_CONTAINER_NOEXCEPT + const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW { return const_iterator(this->non_const_icont().end()); } //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning @@ -520,7 +569,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT + const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW { return const_reverse_iterator(this->cend()); } //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end @@ -529,7 +578,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT + const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW { return const_reverse_iterator(this->cbegin()); } ////////////////////////////////////////////// @@ -543,7 +592,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - bool empty() const BOOST_CONTAINER_NOEXCEPT + bool empty() const BOOST_NOEXCEPT_OR_NOTHROW { return !this->size(); } //! <b>Effects</b>: Returns the number of the elements contained in the list. @@ -551,7 +600,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - size_type size() const BOOST_CONTAINER_NOEXCEPT + size_type size() const BOOST_NOEXCEPT_OR_NOTHROW { return this->icont().size(); } //! <b>Effects</b>: Returns the largest possible size of the list. @@ -559,7 +608,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - size_type max_size() const BOOST_CONTAINER_NOEXCEPT + size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW { return AllocHolder::max_size(); } //! <b>Effects</b>: Inserts or erases elements at the end such that @@ -603,7 +652,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - reference front() BOOST_CONTAINER_NOEXCEPT + reference front() BOOST_NOEXCEPT_OR_NOTHROW { return *this->begin(); } //! <b>Requires</b>: !empty() @@ -614,7 +663,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_reference front() const BOOST_CONTAINER_NOEXCEPT + const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW { return *this->begin(); } //! <b>Requires</b>: !empty() @@ -625,7 +674,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - reference back() BOOST_CONTAINER_NOEXCEPT + reference back() BOOST_NOEXCEPT_OR_NOTHROW { return *(--this->end()); } //! <b>Requires</b>: !empty() @@ -636,7 +685,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant. - const_reference back() const BOOST_CONTAINER_NOEXCEPT + const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW { return *(--this->end()); } ////////////////////////////////////////////// @@ -645,7 +694,7 @@ // ////////////////////////////////////////////// - #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) + #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! <b>Effects</b>: Inserts an object of type T constructed with //! std::forward<Args>(args)... in the end of the list. @@ -655,7 +704,7 @@ //! //! <b>Complexity</b>: Constant template <class... Args> - void emplace_back(Args&&... args) + void emplace_back(BOOST_FWD_REF(Args)... args) { this->emplace(this->cend(), boost::forward<Args>(args)...); } //! <b>Effects</b>: Inserts an object of type T constructed with @@ -666,7 +715,7 @@ //! //! <b>Complexity</b>: Constant template <class... Args> - void emplace_front(Args&&... args) + void emplace_front(BOOST_FWD_REF(Args)... args) { this->emplace(this->cbegin(), boost::forward<Args>(args)...); } //! <b>Effects</b>: Inserts an object of type T constructed with @@ -677,42 +726,34 @@ //! //! <b>Complexity</b>: Constant template <class... Args> - iterator emplace(const_iterator p, Args&&... args) + iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args) { NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...)); return iterator(this->icont().insert(p.get(), *pnode)); } - #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING + #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - #define BOOST_PP_LOCAL_MACRO(n) \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - void emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { \ - this->emplace(this->cend() \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \ - } \ - \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - void emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { \ - this->emplace(this->cbegin() \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \ - } \ - \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - iterator emplace(const_iterator p \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { \ - NodePtr pnode (AllocHolder::create_node \ - (BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \ - return iterator(this->icont().insert(p.get(), *pnode)); \ - } \ - //! - #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) - #include BOOST_PP_LOCAL_ITERATE() + #define BOOST_CONTAINER_LIST_EMPLACE_CODE(N) \ + BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ + void emplace_back(BOOST_MOVE_UREF##N)\ + { this->emplace(this->cend() BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\ + \ + BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ + void emplace_front(BOOST_MOVE_UREF##N)\ + { this->emplace(this->cbegin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\ + \ + BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ + iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ + {\ + NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\ + return iterator(this->icont().insert(p.get(), *pnode));\ + }\ + // + BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_LIST_EMPLACE_CODE) + #undef BOOST_CONTAINER_LIST_EMPLACE_CODE - #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING + #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! <b>Effects</b>: Inserts a copy of x at the beginning of the list. @@ -724,7 +765,7 @@ void push_front(const T &x); //! <b>Effects</b>: Constructs a new element in the beginning of the list - //! and moves the resources of mx to this new element. + //! and moves the resources of x to this new element. //! //! <b>Throws</b>: If memory allocation throws. //! @@ -744,7 +785,7 @@ void push_back(const T &x); //! <b>Effects</b>: Constructs a new element in the end of the list - //! and moves the resources of mx to this new element. + //! and moves the resources of x to this new element. //! //! <b>Throws</b>: If memory allocation throws. //! @@ -755,27 +796,27 @@ #endif #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) - //! <b>Requires</b>: position must be a valid iterator of *this. + //! <b>Requires</b>: p must be a valid iterator of *this. //! - //! <b>Effects</b>: Insert a copy of x before position. + //! <b>Effects</b>: Insert a copy of x before p. //! //! <b>Returns</b>: an iterator to the inserted element. //! //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws. //! //! <b>Complexity</b>: Amortized constant time. - iterator insert(const_iterator position, const T &x); + iterator insert(const_iterator p, const T &x); - //! <b>Requires</b>: position must be a valid iterator of *this. + //! <b>Requires</b>: p must be a valid iterator of *this. //! - //! <b>Effects</b>: Insert a new element before position with mx's resources. + //! <b>Effects</b>: Insert a new element before p with x's resources. //! //! <b>Returns</b>: an iterator to the inserted element. //! //! <b>Throws</b>: If memory allocation throws. //! //! <b>Complexity</b>: Amortized constant time. - iterator insert(const_iterator position, T &&x); + iterator insert(const_iterator p, T &&x); #else BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator) #endif @@ -804,14 +845,14 @@ //! <b>Throws</b>: If memory allocation throws, T's constructor from a //! dereferenced InpIt throws. //! - //! <b>Complexity</b>: Linear to std::distance [first, last). + //! <b>Complexity</b>: Linear to distance [first, last). template <class InpIt> iterator insert(const_iterator p, InpIt first, InpIt last #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < !container_detail::is_convertible<InpIt, size_type>::value && (container_detail::is_input_iterator<InpIt>::value - || container_detail::is_same<alloc_version, allocator_v1>::value + || container_detail::is_same<alloc_version, version_1>::value ) >::type * = 0 #endif @@ -835,7 +876,7 @@ , typename container_detail::enable_if_c < !container_detail::is_convertible<FwdIt, size_type>::value && !(container_detail::is_input_iterator<FwdIt>::value - || container_detail::is_same<alloc_version, allocator_v1>::value + || container_detail::is_same<alloc_version, version_1>::value ) >::type * = 0 ) @@ -844,17 +885,32 @@ insertion_functor func(this->icont(), p.get()); iterator before_p(p.get()); --before_p; - this->allocate_many_and_construct(first, std::distance(first, last), func); + this->allocate_many_and_construct(first, boost::container::iterator_distance(first, last), func); return ++before_p; } #endif +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! <b>Requires</b>: p must be a valid iterator of *this. + //! + //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p. + //! + //! <b>Returns</b>: an iterator to the first inserted element or p if if.begin() == il.end(). + //! + //! <b>Throws</b>: If memory allocation throws, T's constructor from a + //! dereferenced std::initializer_list iterator throws. + //! + //! <b>Complexity</b>: Linear to distance [il.begin(), il.end()). + iterator insert(const_iterator p, std::initializer_list<value_type> il) + { return insert(p, il.begin(), il.end()); } +#endif + //! <b>Effects</b>: Removes the first element from the list. //! //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Amortized constant time. - void pop_front() BOOST_CONTAINER_NOEXCEPT + void pop_front() BOOST_NOEXCEPT_OR_NOTHROW { this->erase(this->cbegin()); } //! <b>Effects</b>: Removes the last element from the list. @@ -862,7 +918,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Amortized constant time. - void pop_back() BOOST_CONTAINER_NOEXCEPT + void pop_back() BOOST_NOEXCEPT_OR_NOTHROW { const_iterator tmp = this->cend(); this->erase(--tmp); } //! <b>Requires</b>: p must be a valid iterator of *this. @@ -872,7 +928,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Amortized constant time. - iterator erase(const_iterator p) BOOST_CONTAINER_NOEXCEPT + iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->icont().erase_and_dispose(p.get(), Destroyer(this->node_alloc()))); } //! <b>Requires</b>: first and last must be valid iterator to elements in *this. @@ -882,7 +938,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Linear to the distance between first and last. - iterator erase(const_iterator first, const_iterator last) BOOST_CONTAINER_NOEXCEPT + iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version())); } //! <b>Effects</b>: Swaps the contents of *this and x. @@ -891,6 +947,8 @@ //! //! <b>Complexity</b>: Constant. void swap(list& x) + BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value + || allocator_traits_type::is_always_equal::value) { AllocHolder::swap(x); } //! <b>Effects</b>: Erases all the elements of the list. @@ -898,7 +956,7 @@ //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Linear to the number of elements in the list. - void clear() BOOST_CONTAINER_NOEXCEPT + void clear() BOOST_NOEXCEPT_OR_NOTHROW { AllocHolder::clear(alloc_version()); } ////////////////////////////////////////////// @@ -919,7 +977,7 @@ //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of //! this list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list& x) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, list& x) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this != &x); BOOST_ASSERT(this->node_alloc() == x.node_alloc()); @@ -938,7 +996,7 @@ //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of //! this list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, BOOST_RV_REF(list) x) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, BOOST_RV_REF(list) x) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast<list&>(x)); } //! <b>Requires</b>: p must point to an element contained @@ -955,7 +1013,7 @@ //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list &x, const_iterator i) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, list &x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW { //BOOST_ASSERT(this != &x); BOOST_ASSERT(this->node_alloc() == x.node_alloc()); @@ -976,7 +1034,7 @@ //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator i) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast<list&>(x), i); } //! <b>Requires</b>: p must point to an element contained @@ -992,7 +1050,7 @@ //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list &x, const_iterator first, const_iterator last) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, list &x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().splice(p.get(), x.icont(), first.get(), last.get()); @@ -1011,12 +1069,12 @@ //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast<list&>(x), first, last); } //! <b>Requires</b>: p must point to an element contained //! by this list. first and last must point to elements contained in list x. - //! n == std::distance(first, last). this' allocator and x's allocator shall compare equal + //! n == distance(first, last). this' allocator and x's allocator shall compare equal //! //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. @@ -1029,7 +1087,7 @@ //! list. Iterators of this list and all the references are not invalidated. //! //! <b>Note</b>: Non-standard extension - void splice(const_iterator p, list &x, const_iterator first, const_iterator last, size_type n) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, list &x, const_iterator first, const_iterator last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().splice(p.get(), x.icont(), first.get(), last.get(), n); @@ -1037,7 +1095,7 @@ //! <b>Requires</b>: p must point to an element contained //! by this list. first and last must point to elements contained in list x. - //! n == std::distance(first, last). this' allocator and x's allocator shall compare equal + //! n == distance(first, last). this' allocator and x's allocator shall compare equal //! //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. @@ -1050,7 +1108,7 @@ //! list. Iterators of this list and all the references are not invalidated. //! //! <b>Note</b>: Non-standard extension - void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last, size_type n) BOOST_CONTAINER_NOEXCEPT + void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast<list&>(x), first, last, n); } //! <b>Effects</b>: Removes all the elements that compare equal to value. @@ -1062,7 +1120,7 @@ //! <b>Note</b>: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. void remove(const T& value) - { this->remove_if(equal_to_value(value)); } + { this->remove_if(equal_to_value_type(value)); } //! <b>Effects</b>: Removes all the elements for which a specified //! predicate is satisfied. @@ -1076,8 +1134,8 @@ template <class Pred> void remove_if(Pred pred) { - typedef ValueCompareToNodeCompare<Pred> Predicate; - this->icont().remove_and_dispose_if(Predicate(pred), Destroyer(this->node_alloc())); + typedef value_to_node_compare<Node, Pred> value_to_node_compare_type; + this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc())); } //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent @@ -1104,8 +1162,8 @@ template <class BinaryPredicate> void unique(BinaryPredicate binary_pred) { - typedef ValueCompareToNodeCompare<BinaryPredicate> Predicate; - this->icont().unique_and_dispose(Predicate(binary_pred), Destroyer(this->node_alloc())); + typedef value_to_node_compare<Node, BinaryPredicate> value_to_node_compare_type; + this->icont().unique_and_dispose(value_to_node_compare_type(binary_pred), Destroyer(this->node_alloc())); } //! <b>Requires</b>: The lists x and *this must be distinct. @@ -1154,8 +1212,8 @@ void merge(list &x, const StrictWeakOrdering &comp) { BOOST_ASSERT(this->node_alloc() == x.node_alloc()); - this->icont().merge(x.icont(), - ValueCompareToNodeCompare<StrictWeakOrdering>(comp)); + typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type; + this->icont().merge(x.icont(), value_to_node_compare_type(comp)); } //! <b>Requires</b>: p must be a comparison function that induces a strict weak @@ -1182,7 +1240,7 @@ //! <b>Throws</b>: If comparison throws. //! //! <b>Notes</b>: Iterators and references are not invalidated. - //! + //! //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N //! is the list's size. void sort() @@ -1203,7 +1261,8 @@ // nothing if the list has length 0 or 1. if (this->size() < 2) return; - this->icont().sort(ValueCompareToNodeCompare<StrictWeakOrdering>(comp)); + typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type; + this->icont().sort(value_to_node_compare_type(comp)); } //! <b>Effects</b>: Reverses the order of elements in the list. @@ -1213,10 +1272,52 @@ //! <b>Complexity</b>: This function is linear time. //! //! <b>Note</b>: Iterators and references are not invalidated - void reverse() BOOST_CONTAINER_NOEXCEPT - { this->icont().reverse(); } + void reverse() BOOST_NOEXCEPT_OR_NOTHROW + { this->icont().reverse(); } - /// @cond + //! <b>Effects</b>: Returns true if x and y are equal + //! + //! <b>Complexity</b>: Linear to the number of elements in the container. + friend bool operator==(const list& x, const list& y) + { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } + + //! <b>Effects</b>: Returns true if x and y are unequal + //! + //! <b>Complexity</b>: Linear to the number of elements in the container. + friend bool operator!=(const list& x, const list& y) + { return !(x == y); } + + //! <b>Effects</b>: Returns true if x is less than y + //! + //! <b>Complexity</b>: Linear to the number of elements in the container. + friend bool operator<(const list& x, const list& y) + { return boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } + + //! <b>Effects</b>: Returns true if x is greater than y + //! + //! <b>Complexity</b>: Linear to the number of elements in the container. + friend bool operator>(const list& x, const list& y) + { return y < x; } + + //! <b>Effects</b>: Returns true if x is equal or less than y + //! + //! <b>Complexity</b>: Linear to the number of elements in the container. + friend bool operator<=(const list& x, const list& y) + { return !(y < x); } + + //! <b>Effects</b>: Returns true if x is equal or greater than y + //! + //! <b>Complexity</b>: Linear to the number of elements in the container. + friend bool operator>=(const list& x, const list& y) + { return !(x < y); } + + //! <b>Effects</b>: x.swap(y) + //! + //! <b>Complexity</b>: Constant. + friend void swap(list& x, list& y) + { x.swap(y); } + + #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED private: bool priv_try_shrink(size_type new_size) @@ -1259,13 +1360,13 @@ return iterator(this->icont().insert(p.get(), *tmp)); } - void priv_push_back (const T &x) + void priv_push_back (const T &x) { this->insert(this->cend(), x); } void priv_push_back (BOOST_RV_REF(T) x) { this->insert(this->cend(), boost::move(x)); } - void priv_push_front (const T &x) + void priv_push_front (const T &x) { this->insert(this->cbegin(), x); } void priv_push_front (BOOST_RV_REF(T) x) @@ -1303,66 +1404,11 @@ bool operator()(const value_type &a, const value_type &b) const { return a == b; } }; - /// @endcond + #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED }; -template <class T, class Allocator> -inline bool operator==(const list<T,Allocator>& x, const list<T,Allocator>& y) -{ - if(x.size() != y.size()){ - return false; - } - typedef typename list<T,Allocator>::const_iterator const_iterator; - const_iterator end1 = x.end(); - - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; -} - -template <class T, class Allocator> -inline bool operator<(const list<T,Allocator>& x, - const list<T,Allocator>& y) -{ - return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); -} - -template <class T, class Allocator> -inline bool operator!=(const list<T,Allocator>& x, const list<T,Allocator>& y) -{ - return !(x == y); -} - -template <class T, class Allocator> -inline bool operator>(const list<T,Allocator>& x, const list<T,Allocator>& y) -{ - return y < x; -} - -template <class T, class Allocator> -inline bool operator<=(const list<T,Allocator>& x, const list<T,Allocator>& y) -{ - return !(y < x); -} - -template <class T, class Allocator> -inline bool operator>=(const list<T,Allocator>& x, const list<T,Allocator>& y) -{ - return !(x < y); -} - -template <class T, class Allocator> -inline void swap(list<T, Allocator>& x, list<T, Allocator>& y) -{ - x.swap(y); -} - -/// @cond +#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED } //namespace container { @@ -1370,12 +1416,15 @@ //!specialization for optimizations template <class T, class Allocator> struct has_trivial_destructor_after_move<boost::container::list<T, Allocator> > - : public ::boost::has_trivial_destructor_after_move<Allocator> -{}; +{ + typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; + static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value && + ::boost::has_trivial_destructor_after_move<pointer>::value; +}; namespace container { -/// @endcond +#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED }}