1 /* Copyright 2003-2020 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_ALLOCATOR_TRAITS_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_ALLOCATOR_TRAITS_HPP
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
18 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
21 #include <boost/detail/workaround.hpp>
22 #include <boost/move/core.hpp>
23 #include <boost/move/utility_core.hpp>
24 #include <boost/multi_index/detail/vartempl_support.hpp>
25 #include <boost/type_traits/integral_constant.hpp>
31 namespace multi_index{
35 /* poor man's replacement of std::allocator_traits */
37 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
39 template<typename Allocator>
40 struct allocator_traits:std::allocator_traits<Allocator>
42 /* wrap std::allocator_traits alias templates for use in C++03 codebase */
44 typedef std::allocator_traits<Allocator> super;
49 typedef typename super::template rebind_alloc<T> type;
55 typedef typename super::template rebind_traits<T> type;
61 /* not a full std::allocator_traits rewrite (not needed) */
63 template<typename Allocator>
64 struct allocator_traits
66 typedef Allocator allocator_type;
67 typedef typename Allocator::value_type value_type;
68 typedef typename Allocator::pointer pointer;
69 typedef typename Allocator::const_pointer const_pointer;
71 /* [const_]void_pointer not provided as boost::pointer_traits's
72 * rebind_to has been seen to fail with things like
73 * boost::interprocess::offset_ptr in relatively old environments.
76 typedef typename Allocator::difference_type difference_type;
77 typedef typename Allocator::size_type size_type;
79 typedef boost::false_type propagate_on_container_copy_assignment;
80 typedef boost::false_type propagate_on_container_move_assignment;
81 typedef boost::false_type propagate_on_container_swap;
86 typedef typename Allocator::template rebind<T>::other type;
92 typedef allocator_traits<typename rebind_alloc<T>::type> type;
95 static pointer allocate(Allocator& a,size_type n){return a.allocate(n);}
96 static pointer allocate(Allocator& a,size_type n,const_pointer p)
97 /* should've been const_void_pointer p */
98 {return a.allocate(n,p);}
99 static void deallocate(Allocator& a,pointer p,size_type n)
102 static void construct(Allocator&,T* p,const T& x)
103 {::new (static_cast<void*>(p)) T(x);}
105 static void construct(Allocator&,T* p,BOOST_RV_REF(T) x)
106 {::new (static_cast<void*>(p)) T(boost::move(x));}
108 template<typename T,BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
109 static void construct(Allocator&,T* p,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
111 vartempl_placement_new(p,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
114 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
115 /* MSVC issues spurious warnings about unreferencend formal parameters in
116 * destroy<T> when T is a class with trivial dtor.
119 #pragma warning(push)
120 #pragma warning(disable:4100)
124 static void destroy(Allocator&,T* p){p->~T();}
126 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
130 static size_type max_size(Allocator& a)BOOST_NOEXCEPT{return a.max_size();}
132 static Allocator select_on_container_copy_construction(const Allocator& a)
140 template<typename Allocator,typename T>
141 struct rebind_alloc_for
143 typedef typename allocator_traits<Allocator>::
144 template rebind_alloc<T>::type type;
147 } /* namespace multi_index::detail */
149 } /* namespace multi_index */
151 } /* namespace boost */