]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/multi_index/detail/allocator_traits.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / multi_index / detail / allocator_traits.hpp
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)
5 *
6 * See http://www.boost.org/libs/multi_index for library home page.
7 */
8
9 #ifndef BOOST_MULTI_INDEX_DETAIL_ALLOCATOR_TRAITS_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_ALLOCATOR_TRAITS_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17
18 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
19 #include <memory>
20 #else
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>
26 #include <new>
27 #endif
28
29 namespace boost{
30
31 namespace multi_index{
32
33 namespace detail{
34
35 /* poor man's replacement of std::allocator_traits */
36
37 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
38
39 template<typename Allocator>
40 struct allocator_traits:std::allocator_traits<Allocator>
41 {
42 /* wrap std::allocator_traits alias templates for use in C++03 codebase */
43
44 typedef std::allocator_traits<Allocator> super;
45
46 template<typename T>
47 struct rebind_alloc
48 {
49 typedef typename super::template rebind_alloc<T> type;
50 };
51
52 template<typename T>
53 struct rebind_traits
54 {
55 typedef typename super::template rebind_traits<T> type;
56 };
57 };
58
59 #else
60
61 /* not a full std::allocator_traits rewrite (not needed) */
62
63 template<typename Allocator>
64 struct allocator_traits
65 {
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;
70
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.
74 */
75
76 typedef typename Allocator::difference_type difference_type;
77 typedef typename Allocator::size_type size_type;
78
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;
82
83 template<typename T>
84 struct rebind_alloc
85 {
86 typedef typename Allocator::template rebind<T>::other type;
87 };
88
89 template<typename T>
90 struct rebind_traits
91 {
92 typedef allocator_traits<typename rebind_alloc<T>::type> type;
93 };
94
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)
100 {a.deallocate(p,n);}
101 template<typename T>
102 static void construct(Allocator&,T* p,const T& x)
103 {::new (static_cast<void*>(p)) T(x);}
104 template<typename T>
105 static void construct(Allocator&,T* p,BOOST_RV_REF(T) x)
106 {::new (static_cast<void*>(p)) T(boost::move(x));}
107
108 template<typename T,BOOST_MULTI_INDEX_TEMPLATE_PARAM_PACK>
109 static void construct(Allocator&,T* p,BOOST_MULTI_INDEX_FUNCTION_PARAM_PACK)
110 {
111 vartempl_placement_new(p,BOOST_MULTI_INDEX_FORWARD_PARAM_PACK);
112 }
113
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.
117 */
118
119 #pragma warning(push)
120 #pragma warning(disable:4100)
121 #endif
122
123 template<typename T>
124 static void destroy(Allocator&,T* p){p->~T();}
125
126 #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
127 #pragma warning(pop)
128 #endif
129
130 static size_type max_size(Allocator& a)BOOST_NOEXCEPT{return a.max_size();}
131
132 static Allocator select_on_container_copy_construction(const Allocator& a)
133 {
134 return a;
135 }
136 };
137
138 #endif
139
140 template<typename Allocator,typename T>
141 struct rebind_alloc_for
142 {
143 typedef typename allocator_traits<Allocator>::
144 template rebind_alloc<T>::type type;
145 };
146
147 } /* namespace multi_index::detail */
148
149 } /* namespace multi_index */
150
151 } /* namespace boost */
152
153 #endif