diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:22:41 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:22:41 +0900 |
commit | 3c1df2168531ad5580076ae08d529054689aeedd (patch) | |
tree | 941aff6f86393eecacddfec252a8508c7e8351c9 /boost/multi_index_container.hpp | |
parent | d6a306e745acfee00e81ccaf3324a2a03516db41 (diff) | |
download | boost-3c1df2168531ad5580076ae08d529054689aeedd.tar.gz boost-3c1df2168531ad5580076ae08d529054689aeedd.tar.bz2 boost-3c1df2168531ad5580076ae08d529054689aeedd.zip |
Imported Upstream version 1.70.0upstream/1.70.0
Diffstat (limited to 'boost/multi_index_container.hpp')
-rw-r--r-- | boost/multi_index_container.hpp | 114 |
1 files changed, 63 insertions, 51 deletions
diff --git a/boost/multi_index_container.hpp b/boost/multi_index_container.hpp index b50bdbc90a..72e42332d9 100644 --- a/boost/multi_index_container.hpp +++ b/boost/multi_index_container.hpp @@ -17,12 +17,11 @@ #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ #include <algorithm> -#include <memory> #include <boost/core/addressof.hpp> -#include <boost/detail/allocator_utilities.hpp> #include <boost/detail/no_exceptions_support.hpp> #include <boost/detail/workaround.hpp> #include <boost/move/core.hpp> +#include <boost/move/utility_core.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/contains.hpp> #include <boost/mpl/find_if.hpp> @@ -33,6 +32,7 @@ #include <boost/multi_index_container_fwd.hpp> #include <boost/multi_index/detail/access_specifier.hpp> #include <boost/multi_index/detail/adl_swap.hpp> +#include <boost/multi_index/detail/allocator_traits.hpp> #include <boost/multi_index/detail/base_type.hpp> #include <boost/multi_index/detail/do_not_copy_elements_tag.hpp> #include <boost/multi_index/detail/converter.hpp> @@ -85,25 +85,20 @@ namespace multi_index{ template<typename Value,typename IndexSpecifierList,typename Allocator> class multi_index_container: private ::boost::base_from_member< - typename boost::detail::allocator::rebind_to< + typename detail::rebind_alloc_for< Allocator, typename detail::multi_index_node_type< Value,IndexSpecifierList,Allocator>::type - >::type>, + >::type + >, BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS detail::header_holder< -#ifndef BOOST_NO_CXX11_ALLOCATOR - typename std::allocator_traits< -#endif - typename boost::detail::allocator::rebind_to< + typename detail::allocator_traits< + typename detail::rebind_alloc_for< Allocator, typename detail::multi_index_node_type< Value,IndexSpecifierList,Allocator>::type >::type -#ifdef BOOST_NO_CXX11_ALLOCATOR - ::pointer, -#else >::pointer, -#endif multi_index_container<Value,IndexSpecifierList,Allocator> >, public detail::multi_index_base_type< Value,IndexSpecifierList,Allocator>::type @@ -129,22 +124,17 @@ private: typedef typename detail::multi_index_base_type< Value,IndexSpecifierList,Allocator>::type super; - typedef typename - boost::detail::allocator::rebind_to< + typedef typename detail::rebind_alloc_for< Allocator, typename super::node_type - >::type node_allocator; -#ifdef BOOST_NO_CXX11_ALLOCATOR - typedef typename node_allocator::pointer node_pointer; -#else - typedef std::allocator_traits<node_allocator> node_allocator_traits; - typedef typename node_allocator_traits::pointer node_pointer; -#endif + >::type node_allocator; + typedef detail::allocator_traits<node_allocator> node_alloc_traits; + typedef typename node_alloc_traits::pointer node_pointer; typedef ::boost::base_from_member< - node_allocator> bfm_allocator; + node_allocator> bfm_allocator; typedef detail::header_holder< node_pointer, - multi_index_container> bfm_header; + multi_index_container> bfm_header; public: /* All types are inherited from super, a few are explicitly @@ -160,6 +150,7 @@ public: typedef typename super::const_iterator_type_list const_iterator_type_list; typedef typename super::value_type value_type; typedef typename super::final_allocator_type allocator_type; + typedef typename super::size_type size_type; typedef typename super::iterator iterator; typedef typename super::const_iterator const_iterator; @@ -547,20 +538,34 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: node_type* allocate_node() { -#ifdef BOOST_NO_CXX11_ALLOCATOR - return &*bfm_allocator::member.allocate(1); -#else - return &*node_allocator_traits::allocate(bfm_allocator::member,1); -#endif + return &*node_alloc_traits::allocate(bfm_allocator::member,1); } void deallocate_node(node_type* x) { -#ifdef BOOST_NO_CXX11_ALLOCATOR - bfm_allocator::member.deallocate(static_cast<node_pointer>(x),1); -#else - node_allocator_traits::deallocate(bfm_allocator::member,static_cast<node_pointer>(x),1); -#endif + node_alloc_traits::deallocate( + bfm_allocator::member,static_cast<node_pointer>(x),1); + } + + void construct_value(node_type* x,const Value& v) + { + node_alloc_traits::construct( + bfm_allocator::member,boost::addressof(x->value()),v); + } + + void construct_value(node_type* x,BOOST_RV_REF(Value) v) + { + node_alloc_traits::construct( + bfm_allocator::member,boost::addressof(x->value()),boost::move(v)); + } + + BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG( + void,construct_value,vartempl_construct_value_impl,node_type*,x) + + void destroy_value(node_type* x) + { + node_alloc_traits::destroy( + bfm_allocator::member,boost::addressof(x->value())); } bool empty_()const @@ -568,14 +573,14 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: return node_count==0; } - std::size_t size_()const + size_type size_()const { return node_count; } - std::size_t max_size_()const + size_type max_size_()const { - return static_cast<std::size_t >(-1); + return static_cast<size_type>(-1); } template<typename Variant> @@ -607,7 +612,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: { node_type* x=allocate_node(); BOOST_TRY{ - new(boost::addressof(x->value())) value_type(t); + construct_value(x,t); BOOST_TRY{ node_type* res=super::insert_(x->value(),x,detail::emplaced_tag()); if(res==x){ @@ -615,13 +620,13 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: return std::pair<node_type*,bool>(res,true); } else{ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); deallocate_node(x); return std::pair<node_type*,bool>(res,false); } } BOOST_CATCH(...){ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); BOOST_RETHROW; } BOOST_CATCH_END @@ -649,8 +654,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: { node_type* x=allocate_node(); BOOST_TRY{ - detail::vartempl_placement_new( - boost::addressof(x->value()),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); + construct_value(x,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); BOOST_TRY{ node_type* res=super::insert_(x->value(),x,detail::emplaced_tag()); if(res==x){ @@ -658,13 +662,13 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: return std::pair<node_type*,bool>(res,true); } else{ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); deallocate_node(x); return std::pair<node_type*,bool>(res,false); } } BOOST_CATCH(...){ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); BOOST_RETHROW; } BOOST_CATCH_END @@ -707,7 +711,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: { node_type* x=allocate_node(); BOOST_TRY{ - new(boost::addressof(x->value())) value_type(t); + construct_value(x,t); BOOST_TRY{ node_type* res=super::insert_( x->value(),position,x,detail::emplaced_tag()); @@ -716,13 +720,13 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: return std::pair<node_type*,bool>(res,true); } else{ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); deallocate_node(x); return std::pair<node_type*,bool>(res,false); } } BOOST_CATCH(...){ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); BOOST_RETHROW; } BOOST_CATCH_END @@ -753,8 +757,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: { node_type* x=allocate_node(); BOOST_TRY{ - detail::vartempl_placement_new( - boost::addressof(x->value()),BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); + construct_value(x,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); BOOST_TRY{ node_type* res=super::insert_( x->value(),position,x,detail::emplaced_tag()); @@ -763,13 +766,13 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: return std::pair<node_type*,bool>(res,true); } else{ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); deallocate_node(x); return std::pair<node_type*,bool>(res,false); } } BOOST_CATCH(...){ - boost::detail::allocator::destroy(boost::addressof(x->value())); + destroy_value(x); BOOST_RETHROW; } BOOST_CATCH_END @@ -995,7 +998,16 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS: #endif private: - std::size_t node_count; + template<BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK> + void vartempl_construct_value_impl( + node_type* x,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK) + { + node_alloc_traits::construct( + bfm_allocator::member,boost::addressof(x->value()), + BOOST_MULTI_INDEX_FORWARD_PARAM_PACK); + } + + size_type node_count; #if defined(BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING)&&\ BOOST_WORKAROUND(__MWERKS__,<=0x3003) |