diff options
Diffstat (limited to 'libs/container/bench')
-rw-r--r-- | libs/container/bench/bench_alloc_expand_fwd.cpp | 24 | ||||
-rw-r--r-- | libs/container/bench/bench_set.hpp | 51 | ||||
-rw-r--r-- | libs/container/bench/bench_set_alloc_v2.cpp | 6 | ||||
-rw-r--r-- | libs/container/bench/detail/varray.hpp | 281 | ||||
-rw-r--r-- | libs/container/bench/detail/varray_concept.hpp | 4 | ||||
-rw-r--r-- | libs/container/bench/detail/varray_util.hpp | 419 | ||||
-rw-r--r-- | libs/container/bench/varray.hpp | 6 |
7 files changed, 363 insertions, 428 deletions
diff --git a/libs/container/bench/bench_alloc_expand_fwd.cpp b/libs/container/bench/bench_alloc_expand_fwd.cpp index 1f88da4d2..b3108bcb1 100644 --- a/libs/container/bench/bench_alloc_expand_fwd.cpp +++ b/libs/container/bench/bench_alloc_expand_fwd.cpp @@ -60,32 +60,32 @@ struct stats_traits; template<> struct stats_traits<std::vector> { - template<class T, class A> - static void reset_alloc_stats(std::vector<T, A> &) + template<class T, class Allocator> + static void reset_alloc_stats(std::vector<T, Allocator> &) {} - template<class T, class A> - static std::size_t get_num_alloc(std::vector<T, A> &) + template<class T, class Allocator> + static std::size_t get_num_alloc(std::vector<T, Allocator> &) { return 0; } - template<class T, class A> - static std::size_t get_num_expand(std::vector<T, A> &) + template<class T, class Allocator> + static std::size_t get_num_expand(std::vector<T, Allocator> &) { return 0; } }; template<> struct stats_traits<bc::vector> { - template<class T, class A> - static void reset_alloc_stats(bc::vector<T, A> &v) + template<class T, class Allocator> + static void reset_alloc_stats(bc::vector<T, Allocator> &v) { v.reset_alloc_stats(); } - template<class T, class A> - static std::size_t get_num_alloc(bc::vector<T, A> &v) + template<class T, class Allocator> + static std::size_t get_num_alloc(bc::vector<T, Allocator> &v) { return v.num_alloc; } - template<class T, class A> - static std::size_t get_num_expand(bc::vector<T, A> &v) + template<class T, class Allocator> + static std::size_t get_num_expand(bc::vector<T, Allocator> &v) { return v.num_expand_fwd; } }; diff --git a/libs/container/bench/bench_set.hpp b/libs/container/bench/bench_set.hpp index cdc304395..b94c5a459 100644 --- a/libs/container/bench/bench_set.hpp +++ b/libs/container/bench/bench_set.hpp @@ -13,7 +13,7 @@ #include <iostream> #include <boost/timer/timer.hpp> -#include <algorithm> +#include <algorithm> //sort #include <exception> #include <sstream> #include <iomanip> @@ -23,7 +23,6 @@ using boost::timer::cpu_timer; using boost::timer::cpu_times; using boost::timer::nanosecond_type; -using namespace boost::container; #ifdef NDEBUG static const std::size_t NElements = 1000; @@ -42,10 +41,10 @@ void compare_times(cpu_times time_numerator, cpu_times time_denominator){ std::cout << "----------------------------------------------" << '\n' << std::endl; } -vector<int> sorted_unique_range_int; -vector<int> sorted_range_int; -vector<int> random_unique_range_int; -vector<int> random_range_int; +boost::container::vector<int> sorted_unique_range_int; +boost::container::vector<int> sorted_range_int; +boost::container::vector<int> random_unique_range_int; +boost::container::vector<int> random_range_int; void fill_range_ints() { @@ -69,15 +68,15 @@ void fill_range_ints() std::random_shuffle(random_unique_range_int.begin(), random_unique_range_int.end()); } -vector<string> sorted_unique_range_string; -vector<string> sorted_range_string; -vector<string> random_unique_range_string; -vector<string> random_range_string; +boost::container::vector<boost::container::string> sorted_unique_range_string; +boost::container::vector<boost::container::string> sorted_range_string; +boost::container::vector<boost::container::string> random_unique_range_string; +boost::container::vector<boost::container::string> random_range_string; void fill_range_strings() { - string model_s; - model_s.append(sizeof(string), '*'); + boost::container::string model_s; + model_s.append(sizeof(boost::container::string), '*'); //sorted_unique_range_int sorted_unique_range_string.resize(NElements); @@ -111,7 +110,7 @@ struct range_provider; template<> struct range_provider<int> { - typedef vector<int> type; + typedef boost::container::vector<int> type; static type &sorted_unique() { return sorted_unique_range_int; } @@ -127,9 +126,9 @@ struct range_provider<int> }; template<> -struct range_provider<string> +struct range_provider<boost::container::string> { - typedef vector<string> type; + typedef boost::container::vector<boost::container::string> type; static type &sorted_unique() { return sorted_unique_range_string; } @@ -145,7 +144,7 @@ struct range_provider<string> }; template<typename C> -cpu_times copy_destroy_time(vector<typename C::value_type> &unique_range) +cpu_times copy_destroy_time(boost::container::vector<typename C::value_type> &unique_range) { cpu_timer copy_timer, assign_timer, destroy_timer; @@ -176,7 +175,9 @@ cpu_times copy_destroy_time(vector<typename C::value_type> &unique_range) } template<typename C> -cpu_times construct_time(vector<typename C::value_type> &unique_range, vector<typename C::value_type> &range, const char *RangeType) +cpu_times construct_time( boost::container::vector<typename C::value_type> &unique_range + , boost::container::vector<typename C::value_type> &range + , const char *RangeType) { cpu_timer sur_timer, sr_timer; @@ -206,7 +207,9 @@ cpu_times construct_time(vector<typename C::value_type> &unique_range, vector<ty } template<typename C> -cpu_times insert_time(vector<typename C::value_type> &unique_range, vector<typename C::value_type> &range, const char *RangeType) +cpu_times insert_time( boost::container::vector<typename C::value_type> &unique_range + , boost::container::vector<typename C::value_type> &range + , const char *RangeType) { cpu_timer ur_timer,r_timer; ur_timer.stop();r_timer.stop(); @@ -240,7 +243,7 @@ cpu_times insert_time(vector<typename C::value_type> &unique_range, vector<typen } template<typename Iterator> -bool check_not_end(vector<Iterator> &iterators, Iterator itend, std::size_t number_of_ends = 0) +bool check_not_end(boost::container::vector<Iterator> &iterators, Iterator itend, std::size_t number_of_ends = 0) { std::size_t end_count = 0; for(std::size_t i = 0, max = iterators.size(); i != max; ++i){ @@ -251,7 +254,7 @@ bool check_not_end(vector<Iterator> &iterators, Iterator itend, std::size_t numb } template<typename Iterator> -bool check_all_not_empty(vector< std::pair<Iterator, Iterator > > &iterator_pairs) +bool check_all_not_empty(boost::container::vector< std::pair<Iterator, Iterator > > &iterator_pairs) { for(std::size_t i = 0, max = iterator_pairs.size(); i != max; ++i){ if(iterator_pairs[i].first == iterator_pairs[i].second) @@ -261,7 +264,7 @@ bool check_all_not_empty(vector< std::pair<Iterator, Iterator > > &iterator_pair } template<typename C> -cpu_times search_time(vector<typename C::value_type> &unique_range, const char *RangeType) +cpu_times search_time(boost::container::vector<typename C::value_type> &unique_range, const char *RangeType) { cpu_timer find_timer, lower_timer, upper_timer, equal_range_timer, count_timer; @@ -270,8 +273,8 @@ cpu_times search_time(vector<typename C::value_type> &unique_range, const char * cpu_timer total_time; total_time.resume(); - vector<typename C::iterator> v_it(NElements); - vector< std::pair<typename C::iterator, typename C::iterator> > v_itp(NElements); + boost::container::vector<typename C::iterator> v_it(NElements); + boost::container::vector< std::pair<typename C::iterator, typename C::iterator> > v_itp(NElements); for(std::size_t i = 0; i != NIter; ++i){ //Find @@ -348,7 +351,7 @@ cpu_times search_time(vector<typename C::value_type> &unique_range, const char * } template<typename C> -void extensions_time(vector<typename C::value_type> &sorted_unique_range) +void extensions_time(boost::container::vector<typename C::value_type> &sorted_unique_range) { cpu_timer sur_timer,sur_opt_timer; sur_timer.stop();sur_opt_timer.stop(); diff --git a/libs/container/bench/bench_set_alloc_v2.cpp b/libs/container/bench/bench_set_alloc_v2.cpp index b92759058..9c2fb9bee 100644 --- a/libs/container/bench/bench_set_alloc_v2.cpp +++ b/libs/container/bench/bench_set_alloc_v2.cpp @@ -8,9 +8,9 @@ // ////////////////////////////////////////////////////////////////////////////// -#include "boost/container/set.hpp" -#include "boost/container/allocator.hpp" #include "bench_set.hpp" +#include <boost/container/set.hpp> +#include <boost/container/allocator.hpp> int main() { @@ -19,7 +19,7 @@ int main() fill_range_ints(); fill_range_strings(); - //set<..., allocator_v2> vs. set + //set<..., version_2> vs. set launch_tests< set<int, std::less<int>, allocator<int> >, set<int> > ("set<int, ..., allocator<int>", "set<int>"); launch_tests< set<string, std::less<string>, allocator<string> >, set<string> > diff --git a/libs/container/bench/detail/varray.hpp b/libs/container/bench/detail/varray.hpp index 244c34d55..80f76b642 100644 --- a/libs/container/bench/detail/varray.hpp +++ b/libs/container/bench/detail/varray.hpp @@ -11,32 +11,39 @@ #ifndef BOOST_CONTAINER_DETAIL_VARRAY_HPP #define BOOST_CONTAINER_DETAIL_VARRAY_HPP -#if defined(_MSC_VER) +#ifndef BOOST_CONFIG_HPP +# include <boost/config.hpp> +#endif + +#if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include <boost/container/detail/config_begin.hpp> #include <boost/container/detail/workaround.hpp> -#include <boost/container/detail/preprocessor.hpp> +#include <boost/container/detail/addressof.hpp> +#include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/move/detail/fwd_macros.hpp> +#endif +#include <boost/container/detail/iterator.hpp> #include <boost/container/detail/iterators.hpp> +#include <boost/container/detail/mpl.hpp> +#include <boost/container/detail/type_traits.hpp> +#include <boost/move/adl_move_swap.hpp> //adl_move_swap -#include "varray_util.hpp" -#ifndef BOOST_NO_EXCEPTIONS -#include <stdexcept> -#endif // BOOST_NO_EXCEPTIONS +#include "varray_util.hpp" #include <boost/assert.hpp> #include <boost/config.hpp> -#include <boost/swap.hpp> -#include <boost/integer.hpp> -#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> -#include <boost/type_traits/is_unsigned.hpp> -#include <boost/type_traits/alignment_of.hpp> -#include <boost/type_traits/aligned_storage.hpp> +#ifndef BOOST_NO_EXCEPTIONS +#include <stdexcept> +#endif // BOOST_NO_EXCEPTIONS /** @@ -174,9 +181,9 @@ struct varray_traits typedef varray_error_handler error_handler; - typedef boost::false_type use_memop_in_swap_and_move; - typedef boost::false_type use_optimized_swap; - typedef boost::false_type disable_trivial_init; + typedef false_type use_memop_in_swap_and_move; + typedef false_type use_optimized_swap; + typedef false_type disable_trivial_init; }; /** @@ -218,18 +225,10 @@ class varray > vt; typedef typename vt::error_handler errh; - - BOOST_MPL_ASSERT_MSG( - ( boost::is_unsigned<typename vt::size_type>::value && - sizeof(typename boost::uint_value_t<Capacity>::least) <= sizeof(typename vt::size_type) ), - SIZE_TYPE_IS_TOO_SMALL_FOR_SPECIFIED_CAPACITY, - (varray) - ); - - typedef boost::aligned_storage< + typedef typename aligned_storage< sizeof(Value[Capacity]), - boost::alignment_of<Value[Capacity]>::value - > aligned_storage_type; + boost::container::container_detail::alignment_of<Value[Capacity]>::value + >::type aligned_storage_type; template <typename V, std::size_t C, typename S> friend class varray; @@ -268,9 +267,9 @@ public: //! @brief The const iterator type. typedef const_pointer const_iterator; //! @brief The reverse iterator type. - typedef container_detail::reverse_iterator<iterator> reverse_iterator; + typedef boost::container::reverse_iterator<iterator> reverse_iterator; //! @brief The const reverse iterator. - typedef container_detail::reverse_iterator<const_iterator> const_reverse_iterator; + typedef boost::container::reverse_iterator<const_iterator> const_reverse_iterator; //! @brief The type of a strategy used by the varray. typedef Strategy strategy_type; @@ -836,7 +835,7 @@ public: { namespace sv = varray_detail; - difference_type to_move = std::distance(position, this->end()); + difference_type to_move = boost::container::iterator_distance(position, this->end()); // TODO - should following lines check for exception and revert to the old size? @@ -883,9 +882,7 @@ public: template <typename Iterator> iterator insert(iterator position, Iterator first, Iterator last) { - typedef typename std::iterator_traits<Iterator>::iterator_category category; - this->insert_dispatch(position, first, last, category()); - + this->insert_dispatch(position, first, last); return position; } @@ -937,7 +934,7 @@ public: errh::check_iterator_end_eq(*this, first); errh::check_iterator_end_eq(*this, last); - difference_type n = std::distance(first, last); + difference_type n = boost::container::iterator_distance(first, last); //TODO - add invalid range check? //BOOST_ASSERT_MSG(0 <= n, "invalid range"); @@ -966,8 +963,7 @@ public: template <typename Iterator> void assign(Iterator first, Iterator last) { - typedef typename std::iterator_traits<Iterator>::iterator_category category; - this->assign_dispatch(first, last, category()); // may throw + this->assign_dispatch(first, last); // may throw } //! @pre <tt>count <= capacity()</tt> @@ -1002,7 +998,7 @@ public: } #if !defined(BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE) -#if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! @pre <tt>size() < capacity()</tt> //! //! @brief Inserts a Value constructed with @@ -1073,8 +1069,9 @@ public: ++m_size; // update end sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw - aligned_storage<sizeof(value_type), alignment_of<value_type>::value> temp_storage; - value_type * val_p = static_cast<value_type *>(temp_storage.address()); + typename aligned_storage + <sizeof(value_type), alignment_of<value_type>::value>::type temp_storage; + value_type * val_p = static_cast<value_type*>(static_cast<void*>(&temp_storage)); sv::construct(dti(), val_p, ::boost::forward<Args>(args)...); // may throw sv::scoped_destructor<value_type> d(val_p); sv::assign(position, ::boost::move(*val_p)); // may throw @@ -1083,63 +1080,51 @@ public: return position; } -#else // BOOST_CONTAINER_PERFECT_FORWARDING || BOOST_CONTAINER_DOXYGEN_INVOKED - - #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, _)) \ - { \ - typedef typename vt::disable_trivial_init dti; \ - \ - errh::check_capacity(*this, m_size + 1); /*may throw*/\ - \ - namespace sv = varray_detail; \ - sv::construct(dti(), this->end() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); /*may throw*/\ - ++m_size; /*update end*/ \ - } \ - // - #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) - #include BOOST_PP_LOCAL_ITERATE() - - #define BOOST_PP_LOCAL_MACRO(n) \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - iterator emplace(iterator position BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { \ - typedef typename vt::disable_trivial_init dti; \ - namespace sv = varray_detail; \ - \ - errh::check_iterator_end_eq(*this, position); \ - errh::check_capacity(*this, m_size + 1); /*may throw*/\ - \ - if ( position == this->end() ) \ - { \ - sv::construct(dti(), position BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); /*may throw*/\ - ++m_size; /*update end*/ \ - } \ - else \ - { \ - /* TODO - should following lines check for exception and revert to the old size? */ \ - /* TODO - should move be used only if it's nonthrowing? */ \ - \ - value_type & r = *(this->end() - 1); \ - sv::construct(dti(), this->end(), boost::move(r)); /*may throw*/\ - ++m_size; /*update end*/ \ - sv::move_backward(position, this->end() - 2, this->end() - 1); /*may throw*/\ - \ - aligned_storage<sizeof(value_type), alignment_of<value_type>::value> temp_storage; \ - value_type * val_p = static_cast<value_type *>(temp_storage.address()); \ - sv::construct(dti(), val_p BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); /*may throw*/\ - sv::scoped_destructor<value_type> d(val_p); \ - sv::assign(position, ::boost::move(*val_p)); /*may throw*/\ - } \ - \ - return position; \ - } \ - // - #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) - #include BOOST_PP_LOCAL_ITERATE() - -#endif // BOOST_CONTAINER_PERFECT_FORWARDING || BOOST_CONTAINER_DOXYGEN_INVOKED +#else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || BOOST_CONTAINER_DOXYGEN_INVOKED + + #define BOOST_CONTAINER_VARRAY_EMPLACE_CODE(N) \ + BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ + void emplace_back(BOOST_MOVE_UREF##N)\ + {\ + typedef typename vt::disable_trivial_init dti;\ + errh::check_capacity(*this, m_size + 1);/*may throw*/\ + \ + namespace sv = varray_detail;\ + sv::construct(dti(), this->end() BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ + ++m_size; /*update end*/\ + }\ + \ + BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ + iterator emplace(iterator position BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ + {\ + typedef typename vt::disable_trivial_init dti;\ + namespace sv = varray_detail;\ + errh::check_iterator_end_eq(*this, position);\ + errh::check_capacity(*this, m_size + 1); /*may throw*/\ + if ( position == this->end() ){\ + sv::construct(dti(), position BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ + ++m_size; /*update end*/\ + }\ + else{\ + /* TODO - should following lines check for exception and revert to the old size? */\ + /* TODO - should move be used only if it's nonthrowing? */\ + value_type & r = *(this->end() - 1);\ + sv::construct(dti(), this->end(), boost::move(r));/*may throw*/\ + ++m_size; /*update end*/\ + sv::move_backward(position, this->end() - 2, this->end() - 1);/*may throw*/\ + typename aligned_storage\ + <sizeof(value_type), alignment_of<value_type>::value>::type temp_storage;\ + value_type * val_p = static_cast<value_type*>(static_cast<void*>(&temp_storage));\ + sv::construct(dti(), val_p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\ + sv::scoped_destructor<value_type> d(val_p);\ + sv::assign(position, ::boost::move(*val_p));/*may throw*/\ + }\ + return position;\ + }\ + BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_VARRAY_EMPLACE_CODE) + #undef BOOST_CONTAINER_VARRAY_EMPLACE_CODE + +#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || BOOST_CONTAINER_DOXYGEN_INVOKED #endif // !BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE //! @brief Removes all elements from the container. @@ -1319,7 +1304,7 @@ public: //! Constant O(1). Value * data() { - return boost::addressof(*(this->ptr())); + return (addressof)(*(this->ptr())); } //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range. @@ -1332,7 +1317,7 @@ public: //! Constant O(1). const Value * data() const { - return boost::addressof(*(this->ptr())); + return (addressof)(*(this->ptr())); } @@ -1526,7 +1511,7 @@ private: // @par Complexity // Linear O(N). template <std::size_t C, typename S> - void move_ctor_dispatch(varray<value_type, C, S> & other, boost::true_type /*use_memop*/) + void move_ctor_dispatch(varray<value_type, C, S> & other, true_type /*use_memop*/) { ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size); m_size = other.m_size; @@ -1538,7 +1523,7 @@ private: // @par Complexity // Linear O(N). template <std::size_t C, typename S> - void move_ctor_dispatch(varray<value_type, C, S> & other, boost::false_type /*use_memop*/) + void move_ctor_dispatch(varray<value_type, C, S> & other, false_type /*use_memop*/) { namespace sv = varray_detail; sv::uninitialized_move_if_noexcept(other.begin(), other.end(), this->begin()); // may throw @@ -1550,12 +1535,12 @@ private: // @par Complexity // Linear O(N). template <std::size_t C, typename S> - void move_assign_dispatch(varray<value_type, C, S> & other, boost::true_type /*use_memop*/) + void move_assign_dispatch(varray<value_type, C, S> & other, true_type /*use_memop*/) { this->clear(); ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size); - boost::swap(m_size, other.m_size); + boost::adl_move_swap(m_size, other.m_size); } // @par Throws @@ -1564,7 +1549,7 @@ private: // @par Complexity // Linear O(N). template <std::size_t C, typename S> - void move_assign_dispatch(varray<value_type, C, S> & other, boost::false_type /*use_memop*/) + void move_assign_dispatch(varray<value_type, C, S> & other, false_type /*use_memop*/) { namespace sv = varray_detail; if ( m_size <= static_cast<size_type>(other.size()) ) @@ -1586,24 +1571,24 @@ private: // @par Complexity // Linear O(N). template <std::size_t C, typename S> - void swap_dispatch(varray<value_type, C, S> & other, boost::true_type const& /*use_optimized_swap*/) + void swap_dispatch(varray<value_type, C, S> & other, true_type const& /*use_optimized_swap*/) { typedef typename - boost::mpl::if_c< + if_c< Capacity < C, aligned_storage_type, typename varray<value_type, C, S>::aligned_storage_type >::type storage_type; - storage_type temp; - Value * temp_ptr = reinterpret_cast<Value*>(temp.address()); + storage_type temp_storage; + value_type * temp_ptr = static_cast<value_type*>(static_cast<void*>(&temp_storage)); ::memcpy(temp_ptr, this->data(), sizeof(Value) * this->size()); ::memcpy(this->data(), other.data(), sizeof(Value) * other.size()); ::memcpy(other.data(), temp_ptr, sizeof(Value) * this->size()); - boost::swap(m_size, other.m_size); + boost::adl_move_swap(m_size, other.m_size); } // @par Throws @@ -1612,7 +1597,7 @@ private: // @par Complexity // Linear O(N). template <std::size_t C, typename S> - void swap_dispatch(varray<value_type, C, S> & other, boost::false_type const& /*use_optimized_swap*/) + void swap_dispatch(varray<value_type, C, S> & other, false_type const& /*use_optimized_swap*/) { namespace sv = varray_detail; @@ -1623,46 +1608,45 @@ private: swap_dispatch_impl(this->begin(), this->end(), other.begin(), other.end(), use_memop_in_swap_and_move()); // may throw else swap_dispatch_impl(other.begin(), other.end(), this->begin(), this->end(), use_memop_in_swap_and_move()); // may throw - boost::swap(m_size, other.m_size); + boost::adl_move_swap(m_size, other.m_size); } // @par Throws // Nothing. // @par Complexity // Linear O(N). - void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, boost::true_type const& /*use_memop*/) + void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, true_type const& /*use_memop*/) { - //BOOST_ASSERT_MSG(std::distance(first_sm, last_sm) <= std::distance(first_la, last_la)); + //BOOST_ASSERT_MSG(boost::container::iterator_distance(first_sm, last_sm) <= boost::container::iterator_distance(first_la, last_la)); namespace sv = varray_detail; for (; first_sm != last_sm ; ++first_sm, ++first_la) { - boost::aligned_storage< + typename aligned_storage< sizeof(value_type), - boost::alignment_of<value_type>::value - > temp_storage; - value_type * temp_ptr = reinterpret_cast<value_type*>(temp_storage.address()); - - ::memcpy(temp_ptr, boost::addressof(*first_sm), sizeof(value_type)); - ::memcpy(boost::addressof(*first_sm), boost::addressof(*first_la), sizeof(value_type)); - ::memcpy(boost::addressof(*first_la), temp_ptr, sizeof(value_type)); + alignment_of<value_type>::value + >::type temp_storage; + value_type * temp_ptr = static_cast<value_type*>(static_cast<void*>(&temp_storage)); + ::memcpy(temp_ptr, (addressof)(*first_sm), sizeof(value_type)); + ::memcpy((addressof)(*first_sm), (addressof)(*first_la), sizeof(value_type)); + ::memcpy((addressof)(*first_la), temp_ptr, sizeof(value_type)); } - ::memcpy(first_sm, first_la, sizeof(value_type) * std::distance(first_la, last_la)); + ::memcpy(first_sm, first_la, sizeof(value_type) * boost::container::iterator_distance(first_la, last_la)); } // @par Throws // If Value's move constructor or move assignment throws. // @par Complexity // Linear O(N). - void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, boost::false_type const& /*use_memop*/) + void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, false_type const& /*use_memop*/) { - //BOOST_ASSERT_MSG(std::distance(first_sm, last_sm) <= std::distance(first_la, last_la)); + //BOOST_ASSERT_MSG(boost::container::iterator_distance(first_sm, last_sm) <= boost::container::iterator_distance(first_la, last_la)); namespace sv = varray_detail; for (; first_sm != last_sm ; ++first_sm, ++first_la) { - //boost::swap(*first_sm, *first_la); // may throw + //boost::adl_move_swap(*first_sm, *first_la); // may throw value_type temp(boost::move(*first_sm)); // may throw *first_sm = boost::move(*first_la); // may throw *first_la = boost::move(temp); // may throw @@ -1715,12 +1699,12 @@ private: // @par Complexity // Linear O(N). template <typename Iterator> - void insert_dispatch(iterator position, Iterator first, Iterator last, std::random_access_iterator_tag) + typename iterator_enable_if_tag<Iterator, std::random_access_iterator_tag>::type + insert_dispatch(iterator position, Iterator first, Iterator last) { errh::check_iterator_end_eq(*this, position); - typename boost::iterator_difference<Iterator>::type - count = std::distance(first, last); + size_type count = boost::container::iterator_distance(first, last); errh::check_capacity(*this, m_size + count); // may throw @@ -1743,7 +1727,8 @@ private: // @par Complexity // Linear O(N). template <typename Iterator, typename Category> - void insert_dispatch(iterator position, Iterator first, Iterator last, Category const& /*not_random_access*/) + typename iterator_disable_if_tag<Iterator, std::random_access_iterator_tag>::type + insert_dispatch(iterator position, Iterator first, Iterator last) { errh::check_iterator_end_eq(*this, position); @@ -1751,7 +1736,7 @@ private: { namespace sv = varray_detail; - std::ptrdiff_t d = std::distance(position, this->begin() + Capacity); + std::ptrdiff_t d = boost::container::iterator_distance(position, this->begin() + Capacity); std::size_t count = sv::uninitialized_copy_s(first, last, position, d); // may throw errh::check_capacity(*this, count <= static_cast<std::size_t>(d) ? m_size + count : Capacity + 1); // may throw @@ -1760,8 +1745,7 @@ private: } else { - typename boost::iterator_difference<Iterator>::type - count = std::distance(first, last); + size_type count = boost::container::iterator_distance(first, last); errh::check_capacity(*this, m_size + count); // may throw @@ -1779,7 +1763,7 @@ private: { namespace sv = varray_detail; - difference_type to_move = std::distance(position, this->end()); + difference_type to_move = boost::container::iterator_distance(position, this->end()); // TODO - should following lines check for exception and revert to the old size? @@ -1793,7 +1777,7 @@ private: else { Iterator middle_iter = first; - std::advance(middle_iter, to_move); + boost::container::iterator_advance(middle_iter, to_move); sv::uninitialized_copy(middle_iter, last, this->end()); // may throw m_size += count - to_move; // update end @@ -1810,12 +1794,12 @@ private: // @par Complexity // Linear O(N). template <typename Iterator> - void assign_dispatch(Iterator first, Iterator last, std::random_access_iterator_tag const& /*not_random_access*/) + typename iterator_enable_if_tag<Iterator, std::random_access_iterator_tag>::type + assign_dispatch(Iterator first, Iterator last) { namespace sv = varray_detail; - typename boost::iterator_difference<Iterator>::type - s = std::distance(first, last); + size_type s = boost::container::iterator_distance(first, last); errh::check_capacity(*this, s); // may throw @@ -1838,7 +1822,8 @@ private: // @par Complexity // Linear O(N). template <typename Iterator, typename Category> - void assign_dispatch(Iterator first, Iterator last, Category const& /*not_random_access*/) + typename iterator_disable_if_tag<Iterator, std::random_access_iterator_tag>::type + assign_dispatch(Iterator first, Iterator last) { namespace sv = varray_detail; @@ -1850,7 +1835,7 @@ private: sv::destroy(it, this->end()); - std::ptrdiff_t d = std::distance(it, this->begin() + Capacity); + std::ptrdiff_t d = boost::container::iterator_distance(it, this->begin() + Capacity); std::size_t count = sv::uninitialized_copy_s(first, last, it, d); // may throw s += count; @@ -1861,12 +1846,12 @@ private: pointer ptr() { - return pointer(static_cast<Value*>(m_storage.address())); + return pointer(static_cast<Value*>(static_cast<void*>(&m_storage))); } const_pointer ptr() const { - return const_pointer(static_cast<const Value*>(m_storage.address())); + return pointer(static_cast<const Value*>(static_cast<const void*>(&m_storage))); } size_type m_size; @@ -1896,8 +1881,8 @@ public: typedef pointer iterator; typedef const_pointer const_iterator; - typedef container_detail::reverse_iterator<iterator> reverse_iterator; - typedef container_detail::reverse_iterator<const_iterator> const_reverse_iterator; + typedef boost::container::reverse_iterator<iterator> reverse_iterator; + typedef boost::container::reverse_iterator<const_iterator> const_reverse_iterator; // nothrow varray() {} @@ -1931,7 +1916,7 @@ public: template <typename Iterator> varray(Iterator first, Iterator last) { - errh::check_capacity(*this, std::distance(first, last)); // may throw + errh::check_capacity(*this, boost::container::iterator_distance(first, last)); // may throw } // basic @@ -2001,7 +1986,7 @@ public: template <typename Iterator> void insert(iterator, Iterator first, Iterator last) { - errh::check_capacity(*this, std::distance(first, last)); // may throw + errh::check_capacity(*this, boost::container::iterator_distance(first, last)); // may throw } // basic @@ -2023,7 +2008,7 @@ public: template <typename Iterator> void assign(Iterator first, Iterator last) { - errh::check_capacity(*this, std::distance(first, last)); // may throw + errh::check_capacity(*this, boost::container::iterator_distance(first, last)); // may throw } // basic @@ -2092,8 +2077,8 @@ public: } // nothrow - Value * data() { return boost::addressof(*(this->ptr())); } - const Value * data() const { return boost::addressof(*(this->ptr())); } + Value * data() { return (addressof)(*(this->ptr())); } + const Value * data() const { return (addressof)(*(this->ptr())); } // nothrow iterator begin() { return this->ptr(); } @@ -2145,7 +2130,7 @@ private: template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2> bool operator== (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y) { - return x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin()); + return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } //! @brief Checks if contents of two varrays are not equal. @@ -2179,7 +2164,7 @@ bool operator!= (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y) template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2> bool operator< (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y) { - return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); + return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } //! @brief Lexicographically compares varrays. diff --git a/libs/container/bench/detail/varray_concept.hpp b/libs/container/bench/detail/varray_concept.hpp index 103c60b47..6f044a9ac 100644 --- a/libs/container/bench/detail/varray_concept.hpp +++ b/libs/container/bench/detail/varray_concept.hpp @@ -17,14 +17,14 @@ namespace boost { namespace container { namespace container_detail { namespace c /** * VArrayStrategyConcept * - * \brief Checks strategy for varray<Value,Capacity,Strategy>, which has similarities to std::Allocator + * \brief Checks strategy for varray<Value,Capacity,Strategy>, which has similarities to std::allocator * \ingroup varray */ template<typename Strategy> struct VArrayStrategy { #ifndef DOXYGEN_NO_CONCEPT_MEMBERS - // typedefs are the same as in std::Allocator + // typedefs are the same as in std::allocator typedef typename Strategy::value_type value_type; typedef typename Strategy::size_type size_type; typedef typename Strategy::difference_type difference_type; diff --git a/libs/container/bench/detail/varray_util.hpp b/libs/container/bench/detail/varray_util.hpp index d76d13fe4..8a97142dd 100644 --- a/libs/container/bench/detail/varray_util.hpp +++ b/libs/container/bench/detail/varray_util.hpp @@ -17,26 +17,20 @@ #include <memory> #include <limits> -#include <boost/mpl/if.hpp> -#include <boost/mpl/and.hpp> -#include <boost/mpl/or.hpp> -#include <boost/mpl/int.hpp> - -#include <boost/type_traits/is_same.hpp> -#include <boost/type_traits/remove_const.hpp> -#include <boost/type_traits/remove_reference.hpp> -#include <boost/type_traits/has_trivial_assign.hpp> -#include <boost/type_traits/has_trivial_copy.hpp> -#include <boost/type_traits/has_trivial_constructor.hpp> -#include <boost/type_traits/has_trivial_destructor.hpp> -#include <boost/move/traits.hpp> -#include <boost/iterator/iterator_traits.hpp> - -#include <boost/core/no_exceptions_support.hpp> #include <boost/config.hpp> -#include <boost/move/utility_core.hpp> +#include <boost/core/no_exceptions_support.hpp> + +#include <boost/container/detail/addressof.hpp> +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/move/detail/fwd_macros.hpp> +#endif +#include <boost/container/detail/iterator.hpp> +#include <boost/container/detail/mpl.hpp> +#include <boost/container/detail/type_traits.hpp> + #include <boost/move/algorithm.hpp> -#include <boost/utility/addressof.hpp> +#include <boost/move/traits.hpp> +#include <boost/move/utility_core.hpp> // TODO - move vectors iterators optimization to the other, optional file instead of checking defines? @@ -47,22 +41,24 @@ namespace boost { namespace container { namespace varray_detail { +namespace bcd = ::boost::container::container_detail; + template <typename I> -struct are_elements_contiguous : boost::is_pointer<I> +struct are_elements_contiguous : boost::container::container_detail::is_pointer<I> {}; #if defined(BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION) && !defined(BOOST_NO_EXCEPTIONS) template <typename Pointer> struct are_elements_contiguous< - boost::container::container_detail::vector_const_iterator<Pointer> -> : boost::true_type + bcd::vector_const_iterator<Pointer> +> : bcd::true_type {}; template <typename Pointer> struct are_elements_contiguous< - boost::container::container_detail::vector_iterator<Pointer> -> : boost::true_type + bcd::vector_iterator<Pointer> +> : bcd::true_type {}; #if defined(BOOST_DINKUMWARE_STDLIB) @@ -70,21 +66,21 @@ struct are_elements_contiguous< template <typename T> struct are_elements_contiguous< std::_Vector_const_iterator<T> -> : boost::true_type +> : bcd::true_type {}; template <typename T> struct are_elements_contiguous< std::_Vector_iterator<T> -> : boost::true_type +> : bcd::true_type {}; #elif defined(BOOST_GNU_STDLIB) -template <typename P, typename T, typename A> +template <typename P, typename T, typename Allocator> struct are_elements_contiguous< - __gnu_cxx::__normal_iterator<P, std::vector<T, A> > -> : boost::true_type + __gnu_cxx::__normal_iterator<P, std::vector<T, Allocator> > +> : bcd::true_type {}; #elif defined(_LIBCPP_VERSION) @@ -93,7 +89,7 @@ struct are_elements_contiguous< //template <typename P> //struct are_elements_contiguous< // __wrap_iter<P> -//> : boost::true_type +//> : bcd::true_type //{}; #else // OTHER_STDLIB @@ -104,48 +100,42 @@ struct are_elements_contiguous< #endif // BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION && !BOOST_NO_EXCEPTIONS -}}} // namespace boost::container::varray_detail - -namespace boost { namespace container { namespace varray_detail { - template <typename I, typename O> struct are_corresponding : - ::boost::mpl::and_< - ::boost::is_same< - ::boost::remove_const< - typename ::boost::iterator_value<I>::type + bcd::bool_< + bcd::is_same< + bcd::remove_const< + typename ::boost::container::iterator_traits<I>::value_type >, - ::boost::remove_const< - typename ::boost::iterator_value<O>::type + bcd::remove_const< + typename ::boost::container::iterator_traits<O>::value_type > - >, - are_elements_contiguous<I>, - are_elements_contiguous<O> + >::value && + are_elements_contiguous<I>::value && + are_elements_contiguous<O>::value > {}; template <typename I, typename V> struct is_corresponding_value : - ::boost::is_same< - ::boost::remove_const< - typename ::boost::iterator_value<I>::type - >, - ::boost::remove_const<V> - > + bcd::bool_< + bcd::is_same< + bcd::remove_const<typename ::boost::container::iterator_traits<I>::value_type>, + bcd::remove_const<V> + >::value + > {}; // destroy(I, I) template <typename I> -void destroy_dispatch(I /*first*/, I /*last*/, - boost::true_type const& /*has_trivial_destructor*/) +void destroy_dispatch(I /*first*/, I /*last*/, bcd::true_type const& /*is_trivially_destructible*/) {} template <typename I> -void destroy_dispatch(I first, I last, - boost::false_type const& /*has_trivial_destructor*/) +void destroy_dispatch(I first, I last, bcd::false_type const& /*is_trivially_destructible*/) { - typedef typename boost::iterator_value<I>::type value_type; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; for ( ; first != last ; ++first ) first->~value_type(); } @@ -153,48 +143,45 @@ void destroy_dispatch(I first, I last, template <typename I> void destroy(I first, I last) { - typedef typename boost::iterator_value<I>::type value_type; - destroy_dispatch(first, last, has_trivial_destructor<value_type>()); + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + destroy_dispatch(first, last, bcd::bool_<bcd::is_trivially_destructible<value_type>::value>()); } // destroy(I) template <typename I> void destroy_dispatch(I /*pos*/, - boost::true_type const& /*has_trivial_destructor*/) + bcd::true_type const& /*is_trivially_destructible*/) {} template <typename I> void destroy_dispatch(I pos, - boost::false_type const& /*has_trivial_destructor*/) + bcd::false_type const& /*is_trivially_destructible*/) { - typedef typename boost::iterator_value<I>::type value_type; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; pos->~value_type(); } template <typename I> void destroy(I pos) { - typedef typename boost::iterator_value<I>::type value_type; - destroy_dispatch(pos, has_trivial_destructor<value_type>()); + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + destroy_dispatch(pos, bcd::bool_<bcd::is_trivially_destructible<value_type>::value>()); } // copy(I, I, O) template <typename I, typename O> -inline O copy_dispatch(I first, I last, O dst, - boost::mpl::bool_<true> const& /*use_memmove*/) +inline O copy_dispatch(I first, I last, O dst, bcd::true_type const& /*use_memmove*/) { - typedef typename boost::iterator_value<I>::type value_type; - typename boost::iterator_difference<I>::type d = std::distance(first, last); - - ::memmove(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d); - return dst + d; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + const std::size_t d = boost::container::iterator_distance(first, last); + ::memmove(boost::container::container_detail::addressof(*dst), boost::container::container_detail::addressof(*first), sizeof(value_type) * d); + return dst + d; } template <typename I, typename O> -inline O copy_dispatch(I first, I last, O dst, - boost::mpl::bool_<false> const& /*use_memmove*/) +inline O copy_dispatch(I first, I last, O dst, bcd::false_type const& /*use_memmove*/) { return std::copy(first, last, dst); // may throw } @@ -202,16 +189,12 @@ inline O copy_dispatch(I first, I last, O dst, template <typename I, typename O> inline O copy(I first, I last, O dst) { - typedef typename - ::boost::mpl::and_< - are_corresponding<I, O>, - ::boost::has_trivial_assign< - typename ::boost::iterator_value<O>::type - > - >::type - use_memmove; + typedef bcd::bool_ + < are_corresponding<I, O>::value && + bcd::is_trivially_copy_assignable<typename ::boost::container::iterator_traits<O>::value_type>::value + > use_memmove; - return copy_dispatch(first, last, dst, use_memmove()); // may throw + return copy_dispatch(first, last, dst, use_memmove()); // may throw } // uninitialized_copy(I, I, O) @@ -219,19 +202,18 @@ inline O copy(I first, I last, O dst) template <typename I, typename O> inline O uninitialized_copy_dispatch(I first, I last, O dst, - boost::mpl::bool_<true> const& /*use_memcpy*/) + bcd::true_type const& /*use_memcpy*/) { - typedef typename boost::iterator_value<I>::type value_type; - typename boost::iterator_difference<I>::type d = std::distance(first, last); - - ::memcpy(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d); - return dst + d; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + const std::size_t d = boost::container::iterator_distance(first, last); + ::memcpy(boost::container::container_detail::addressof(*dst), boost::container::container_detail::addressof(*first), sizeof(value_type) * d); + return dst + d; } template <typename I, typename F> inline F uninitialized_copy_dispatch(I first, I last, F dst, - boost::mpl::bool_<false> const& /*use_memcpy*/) + bcd::false_type const& /*use_memcpy*/) { return std::uninitialized_copy(first, last, dst); // may throw } @@ -240,16 +222,11 @@ template <typename I, typename F> inline F uninitialized_copy(I first, I last, F dst) { - typedef typename - ::boost::mpl::and_< - are_corresponding<I, F>, - ::boost::has_trivial_copy< - typename ::boost::iterator_value<F>::type - > - >::type - use_memcpy; - - return uninitialized_copy_dispatch(first, last, dst, use_memcpy()); // may throw + typedef bcd::bool_ + < are_corresponding<I, F>::value && + bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<F>::value_type>::value + > use_memcpy; + return uninitialized_copy_dispatch(first, last, dst, use_memcpy()); // may throw } // uninitialized_move(I, I, O) @@ -257,19 +234,18 @@ F uninitialized_copy(I first, I last, F dst) template <typename I, typename O> inline O uninitialized_move_dispatch(I first, I last, O dst, - boost::mpl::bool_<true> const& /*use_memcpy*/) + bcd::true_type const& /*use_memcpy*/) { - typedef typename boost::iterator_value<I>::type value_type; - typename boost::iterator_difference<I>::type d = std::distance(first, last); - - ::memcpy(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d); - return dst + d; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + const std::size_t d = boost::container::iterator_distance(first, last); + ::memcpy(boost::container::container_detail::addressof(*dst), boost::container::container_detail::addressof(*first), sizeof(value_type) * d); + return dst + d; } template <typename I, typename O> inline O uninitialized_move_dispatch(I first, I last, O dst, - boost::mpl::bool_<false> const& /*use_memcpy*/) + bcd::false_type const& /*use_memcpy*/) { //return boost::uninitialized_move(first, last, dst); // may throw @@ -277,9 +253,9 @@ O uninitialized_move_dispatch(I first, I last, O dst, BOOST_TRY { - typedef typename std::iterator_traits<O>::value_type value_type; + typedef typename boost::container::iterator_traits<O>::value_type value_type; for (; first != last; ++first, ++o ) - new (boost::addressof(*o)) value_type(boost::move(*first)); + new (boost::container::container_detail::addressof(*o)) value_type(boost::move(*first)); } BOOST_CATCH(...) { @@ -295,16 +271,11 @@ template <typename I, typename O> inline O uninitialized_move(I first, I last, O dst) { - typedef typename - ::boost::mpl::and_< - are_corresponding<I, O>, - ::boost::has_trivial_copy< - typename ::boost::iterator_value<O>::type - > - >::type - use_memcpy; - - return uninitialized_move_dispatch(first, last, dst, use_memcpy()); // may throw + typedef bcd::bool_ + < are_corresponding<I, O>::value && + bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<O>::value_type>::value + > use_memcpy; + return uninitialized_move_dispatch(first, last, dst, use_memcpy()); // may throw } // TODO - move uses memmove - implement 2nd version using memcpy? @@ -314,37 +285,31 @@ O uninitialized_move(I first, I last, O dst) template <typename I, typename O> inline O move_dispatch(I first, I last, O dst, - boost::mpl::bool_<true> const& /*use_memmove*/) + bcd::true_type const& /*use_memmove*/) { - typedef typename boost::iterator_value<I>::type value_type; - typename boost::iterator_difference<I>::type d = std::distance(first, last); - - ::memmove(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d); - return dst + d; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + const std::size_t d = boost::container::iterator_distance(first, last); + ::memmove(boost::container::container_detail::addressof(*dst), boost::container::container_detail::addressof(*first), sizeof(value_type)*d ); + return dst + d; } template <typename I, typename O> inline O move_dispatch(I first, I last, O dst, - boost::mpl::bool_<false> const& /*use_memmove*/) + bcd::false_type const& /*use_memmove*/) { - return boost::move(first, last, dst); // may throw + return boost::move(first, last, dst); // may throw } template <typename I, typename O> inline O move(I first, I last, O dst) { - typedef typename - ::boost::mpl::and_< - are_corresponding<I, O>, - ::boost::has_trivial_assign< - typename ::boost::iterator_value<O>::type - > - >::type - use_memmove; - - return move_dispatch(first, last, dst, use_memmove()); // may throw + typedef bcd::bool_ + < are_corresponding<I, O>::value && + bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<O>::value_type>::value + > use_memmove; + return move_dispatch(first, last, dst, use_memmove()); // may throw } // move_backward(BDI, BDI, BDO) @@ -352,20 +317,19 @@ O move(I first, I last, O dst) template <typename BDI, typename BDO> inline BDO move_backward_dispatch(BDI first, BDI last, BDO dst, - boost::mpl::bool_<true> const& /*use_memmove*/) + bcd::true_type const& /*use_memmove*/) { - typedef typename boost::iterator_value<BDI>::type value_type; - typename boost::iterator_difference<BDI>::type d = std::distance(first, last); - + typedef typename ::boost::container::iterator_traits<BDI>::value_type value_type; + const std::size_t d = boost::container::iterator_distance(first, last); BDO foo(dst - d); - ::memmove(boost::addressof(*foo), boost::addressof(*first), sizeof(value_type) * d); + ::memmove(boost::container::container_detail::addressof(*foo), boost::container::container_detail::addressof(*first), sizeof(value_type) * d); return foo; } template <typename BDI, typename BDO> inline BDO move_backward_dispatch(BDI first, BDI last, BDO dst, - boost::mpl::bool_<false> const& /*use_memmove*/) + bcd::false_type const& /*use_memmove*/) { return boost::move_backward(first, last, dst); // may throw } @@ -374,29 +338,21 @@ template <typename BDI, typename BDO> inline BDO move_backward(BDI first, BDI last, BDO dst) { - typedef typename - ::boost::mpl::and_< - are_corresponding<BDI, BDO>, - ::boost::has_trivial_assign< - typename ::boost::iterator_value<BDO>::type - > - >::type - use_memmove; - - return move_backward_dispatch(first, last, dst, use_memmove()); // may throw + typedef bcd::bool_ + < are_corresponding<BDI, BDO>::value && + bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<BDO>::value_type>::value + > use_memmove; + return move_backward_dispatch(first, last, dst, use_memmove()); // may throw } template <typename T> struct has_nothrow_move : public - ::boost::mpl::or_< - boost::mpl::bool_< - ::boost::has_nothrow_move< - typename ::boost::remove_const<T>::type - >::value - >, - boost::mpl::bool_< - ::boost::has_nothrow_move<T>::value - > + bcd::bool_< + ::boost::has_nothrow_move< + typename bcd::remove_const<T>::type + >::value + || + ::boost::has_nothrow_move<T>::value > {}; @@ -404,21 +360,21 @@ struct has_nothrow_move : public template <typename I, typename O> inline -O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<true> const& /*use_move*/) +O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, bcd::true_type const& /*use_move*/) { return uninitialized_move(first, last, dst); } template <typename I, typename O> inline -O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<false> const& /*use_move*/) +O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, bcd::false_type const& /*use_move*/) { return uninitialized_copy(first, last, dst); } template <typename I, typename O> inline O uninitialized_move_if_noexcept(I first, I last, O dst) { - typedef typename has_nothrow_move< - typename ::boost::iterator_value<O>::type - >::type use_move; + typedef has_nothrow_move< + typename ::boost::container::iterator_traits<O>::value_type + > use_move; return uninitialized_move_if_noexcept_dispatch(first, last, dst, use_move()); // may throw } @@ -427,21 +383,21 @@ O uninitialized_move_if_noexcept(I first, I last, O dst) template <typename I, typename O> inline -O move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<true> const& /*use_move*/) +O move_if_noexcept_dispatch(I first, I last, O dst, bcd::true_type const& /*use_move*/) { return move(first, last, dst); } template <typename I, typename O> inline -O move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<false> const& /*use_move*/) +O move_if_noexcept_dispatch(I first, I last, O dst, bcd::false_type const& /*use_move*/) { return copy(first, last, dst); } template <typename I, typename O> inline O move_if_noexcept(I first, I last, O dst) { - typedef typename has_nothrow_move< - typename ::boost::iterator_value<O>::type - >::type use_move; + typedef has_nothrow_move< + typename ::boost::container::iterator_traits<O>::value_type + > use_move; return move_if_noexcept_dispatch(first, last, dst, use_move()); // may throw } @@ -451,34 +407,34 @@ O move_if_noexcept(I first, I last, O dst) template <typename I> inline void uninitialized_fill_dispatch(I first, I last, - boost::true_type const& /*has_trivial_constructor*/, - boost::true_type const& /*disable_trivial_init*/) + bcd::true_type const& /*is_trivially_default_constructible*/, + bcd::true_type const& /*disable_trivial_init*/) {} template <typename I> inline void uninitialized_fill_dispatch(I first, I last, - boost::true_type const& /*has_trivial_constructor*/, - boost::false_type const& /*disable_trivial_init*/) + bcd::true_type const& /*is_trivially_default_constructible*/, + bcd::false_type const& /*disable_trivial_init*/) { - typedef typename boost::iterator_value<I>::type value_type; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; for ( ; first != last ; ++first ) - new (boost::addressof(*first)) value_type(); + new (boost::container::container_detail::addressof(*first)) value_type(); } template <typename I, typename DisableTrivialInit> inline void uninitialized_fill_dispatch(I first, I last, - boost::false_type const& /*has_trivial_constructor*/, + bcd::false_type const& /*is_trivially_default_constructible*/, DisableTrivialInit const& /*not_used*/) { - typedef typename boost::iterator_value<I>::type value_type; + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; I it = first; BOOST_TRY { for ( ; it != last ; ++it ) - new (boost::addressof(*it)) value_type(); // may throw + new (boost::container::container_detail::addressof(*it)) value_type(); // may throw } BOOST_CATCH(...) { @@ -492,35 +448,36 @@ template <typename I, typename DisableTrivialInit> inline void uninitialized_fill(I first, I last, DisableTrivialInit const& disable_trivial_init) { - typedef typename boost::iterator_value<I>::type value_type; - uninitialized_fill_dispatch(first, last, boost::has_trivial_constructor<value_type>(), disable_trivial_init); // may throw + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + uninitialized_fill_dispatch(first, last + , bcd::bool_<bcd::is_trivially_default_constructible<value_type>::value>() + , disable_trivial_init); // may throw } // construct(I) template <typename I> inline -void construct_dispatch(boost::mpl::bool_<true> const& /*dont_init*/, I pos) +void construct_dispatch(bcd::true_type const& /*dont_init*/, I pos) {} template <typename I> inline -void construct_dispatch(boost::mpl::bool_<false> const& /*dont_init*/, I pos) +void construct_dispatch(bcd::false_type const& /*dont_init*/, I pos) { - typedef typename ::boost::iterator_value<I>::type value_type; - new (static_cast<void*>(::boost::addressof(*pos))) value_type(); // may throw + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + new (static_cast<void*>(::boost::container::container_detail::addressof(*pos))) value_type(); // may throw } template <typename DisableTrivialInit, typename I> inline void construct(DisableTrivialInit const&, I pos) { - typedef typename ::boost::iterator_value<I>::type value_type; - typedef typename ::boost::mpl::and_< - boost::has_trivial_constructor<value_type>, - DisableTrivialInit - >::type dont_init; - + typedef typename ::boost::container::iterator_traits<I>::value_type value_type; + bcd::bool_< + bcd::is_trivially_default_constructible<value_type>::value && + DisableTrivialInit::value + > dont_init; construct_dispatch(dont_init(), pos); // may throw } @@ -528,34 +485,29 @@ void construct(DisableTrivialInit const&, I pos) template <typename I, typename V> inline -void construct_dispatch(I pos, V const& v, - boost::mpl::bool_<true> const& /*use_memcpy*/) +void construct_dispatch(I pos, V const& v, bcd::true_type const& /*use_memcpy*/) { - ::memcpy(boost::addressof(*pos), boost::addressof(v), sizeof(V)); + ::memcpy(boost::container::container_detail::addressof(*pos), boost::container::container_detail::addressof(v), sizeof(V)); } template <typename I, typename P> inline void construct_dispatch(I pos, P const& p, - boost::mpl::bool_<false> const& /*use_memcpy*/) + bcd::false_type const& /*use_memcpy*/) { - typedef typename boost::iterator_value<I>::type V; - new (static_cast<void*>(boost::addressof(*pos))) V(p); // may throw + typedef typename ::boost::container::iterator_traits<I>::value_type V; + new (static_cast<void*>(boost::container::container_detail::addressof(*pos))) V(p); // may throw } template <typename DisableTrivialInit, typename I, typename P> inline -void construct(DisableTrivialInit const&, - I pos, P const& p) +void construct(DisableTrivialInit const&, I pos, P const& p) { - typedef typename - ::boost::mpl::and_< - is_corresponding_value<I, P>, - ::boost::has_trivial_copy<P> - >::type - use_memcpy; - - construct_dispatch(pos, p, use_memcpy()); // may throw + typedef bcd::bool_ + < is_corresponding_value<I, P>::value && + bcd::is_trivially_copy_constructible<P>::value + > use_memcpy; + construct_dispatch(pos, p, use_memcpy()); // may throw } // Needed by push_back(V &&) @@ -564,14 +516,14 @@ template <typename DisableTrivialInit, typename I, typename P> inline void construct(DisableTrivialInit const&, I pos, BOOST_RV_REF(P) p) { - typedef typename boost::iterator_value<I>::type V; - new (static_cast<void*>(boost::addressof(*pos))) V(::boost::move(p)); // may throw + typedef typename ::boost::container::iterator_traits<I>::value_type V; + new (static_cast<void*>(boost::container::container_detail::addressof(*pos))) V(::boost::move(p)); // may throw } // Needed by emplace_back() and emplace() #if !defined(BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE) -#if !defined(BOOST_NO_VARIADIC_TEMPLATES) +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template <typename DisableTrivialInit, typename I, class ...Args> inline @@ -579,34 +531,28 @@ void construct(DisableTrivialInit const&, I pos, BOOST_FWD_REF(Args) ...args) { - typedef typename boost::iterator_value<I>::type V; - new (static_cast<void*>(boost::addressof(*pos))) V(::boost::forward<Args>(args)...); // may throw + typedef typename ::boost::container::iterator_traits<I>::value_type V; + new (static_cast<void*>(boost::container::container_detail::addressof(*pos))) V(::boost::forward<Args>(args)...); // may throw } -#else // !BOOST_NO_VARIADIC_TEMPLATES +#else // !BOOST_NO_CXX11_VARIADIC_TEMPLATES // BOOST_NO_RVALUE_REFERENCES -> P0 const& p0 // !BOOST_NO_RVALUE_REFERENCES -> P0 && p0 // which means that version with one parameter may take V const& v -#define BOOST_PP_LOCAL_MACRO(n) \ -template <typename DisableTrivialInit, typename I, typename P BOOST_PP_ENUM_TRAILING_PARAMS(n, typename P) > \ -inline \ -void construct(DisableTrivialInit const&, \ - I pos, \ - BOOST_CONTAINER_PP_PARAM(P, p) \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ -{ \ - typedef typename boost::iterator_value<I>::type V; \ - new \ - (static_cast<void*>(boost::addressof(*pos))) \ - V(p, BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); /*may throw*/ \ -} \ -// -#define BOOST_PP_LOCAL_LIMITS (1, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) -#include BOOST_PP_LOCAL_ITERATE() +#define BOOST_CONTAINER_VARRAY_UTIL_CONSTRUCT_CODE(N) \ +template <typename DisableTrivialInit, typename I, typename P BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\ +inline void construct(DisableTrivialInit const&, I pos, BOOST_FWD_REF(P) p BOOST_MOVE_I##N BOOST_MOVE_UREF##N )\ +{\ + typedef typename ::boost::container::iterator_traits<I>::value_type V;\ + new (static_cast<void*>(boost::container::container_detail::addressof(*pos)))\ + V(::boost::forward<P>(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N); /*may throw*/\ +} +BOOST_MOVE_ITERATE_1TO9(BOOST_CONTAINER_VARRAY_UTIL_CONSTRUCT_CODE) +#undef BOOST_CONTAINER_VARRAY_UTIL_CONSTRUCT_CODE -#endif // !BOOST_NO_VARIADIC_TEMPLATES +#endif // !BOOST_NO_CXX11_VARIADIC_TEMPLATES #endif // !BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE // assign(I, V) @@ -614,15 +560,15 @@ void construct(DisableTrivialInit const&, template <typename I, typename V> inline void assign_dispatch(I pos, V const& v, - boost::mpl::bool_<true> const& /*use_memcpy*/) + bcd::true_type const& /*use_memcpy*/) { - ::memcpy(boost::addressof(*pos), boost::addressof(v), sizeof(V)); + ::memcpy(boost::container::container_detail::addressof(*pos), boost::container::container_detail::addressof(v), sizeof(V)); } template <typename I, typename V> inline void assign_dispatch(I pos, V const& v, - boost::mpl::bool_<false> const& /*use_memcpy*/) + bcd::false_type const& /*use_memcpy*/) { *pos = v; // may throw } @@ -631,14 +577,11 @@ template <typename I, typename V> inline void assign(I pos, V const& v) { - typedef typename - ::boost::mpl::and_< - is_corresponding_value<I, V>, - ::boost::has_trivial_assign<V> - >::type - use_memcpy; - - assign_dispatch(pos, v, use_memcpy()); // may throw + typedef bcd::bool_ + < is_corresponding_value<I, V>::value && + bcd::is_trivially_copy_assignable<V>::value + > use_memcpy; + assign_dispatch(pos, v, use_memcpy()); // may throw } template <typename I, typename V> diff --git a/libs/container/bench/varray.hpp b/libs/container/bench/varray.hpp index 9840e617a..335c33ffe 100644 --- a/libs/container/bench/varray.hpp +++ b/libs/container/bench/varray.hpp @@ -11,7 +11,11 @@ #ifndef BOOST_CONTAINER_VARRAY_HPP #define BOOST_CONTAINER_VARRAY_HPP -#if defined(_MSC_VER) +#ifndef BOOST_CONFIG_HPP +# include <boost/config.hpp> +#endif + +#if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif |