| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
|
2 |
|
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
| 5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/boostorg/url
|
7 |
|
// Official repository: https://github.com/boostorg/url
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_URL_DETAIL_OVER_ALLOCATOR_HPP
|
10 |
|
#ifndef BOOST_URL_DETAIL_OVER_ALLOCATOR_HPP
|
| 11 |
|
#define BOOST_URL_DETAIL_OVER_ALLOCATOR_HPP
|
11 |
|
#define BOOST_URL_DETAIL_OVER_ALLOCATOR_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/config.hpp>
|
13 |
|
#include <boost/config.hpp>
|
| 14 |
|
#include <boost/core/empty_value.hpp>
|
14 |
|
#include <boost/core/empty_value.hpp>
|
| 15 |
|
#include <boost/assert.hpp>
|
15 |
|
#include <boost/assert.hpp>
|
| 16 |
|
#include <boost/type_traits/is_final.hpp>
|
16 |
|
#include <boost/type_traits/is_final.hpp>
|
| 17 |
|
#include <boost/type_traits/type_with_alignment.hpp>
|
17 |
|
#include <boost/type_traits/type_with_alignment.hpp>
|
| 18 |
|
#ifdef BOOST_NO_CXX11_ALLOCATOR
|
18 |
|
#ifdef BOOST_NO_CXX11_ALLOCATOR
|
| 19 |
|
# include <boost/core/allocator_traits.hpp>
|
19 |
|
# include <boost/core/allocator_traits.hpp>
|
| 20 |
|
|
20 |
|
|
| 21 |
|
|
21 |
|
|
| 22 |
|
|
22 |
|
|
| 23 |
|
|
23 |
|
|
| 24 |
|
|
24 |
|
|
| 25 |
|
|
25 |
|
|
| 26 |
|
|
26 |
|
|
| 27 |
|
|
27 |
|
|
| 28 |
|
|
28 |
|
|
| 29 |
|
|
29 |
|
|
| 30 |
|
// This is a workaround for allocator_traits
|
30 |
|
// This is a workaround for allocator_traits
|
| 31 |
|
// implementations which falsely claim C++11
|
31 |
|
// implementations which falsely claim C++11
|
| 32 |
|
|
32 |
|
|
| 33 |
|
#ifdef BOOST_NO_CXX11_ALLOCATOR
|
33 |
|
#ifdef BOOST_NO_CXX11_ALLOCATOR
|
| 34 |
|
|
34 |
|
|
| 35 |
|
|
35 |
|
|
| 36 |
|
boost::allocator_traits<Alloc>;
|
36 |
|
boost::allocator_traits<Alloc>;
|
| 37 |
|
|
37 |
|
|
| 38 |
|
|
38 |
|
|
| 39 |
|
using allocator_traits = std::allocator_traits<Alloc>;
|
39 |
|
using allocator_traits = std::allocator_traits<Alloc>;
|
| 40 |
|
|
40 |
|
|
| 41 |
|
|
41 |
|
|
| 42 |
|
template<class T, class Allocator>
|
42 |
|
template<class T, class Allocator>
|
| 43 |
|
|
43 |
|
|
| 44 |
|
: private empty_value<Allocator>
|
44 |
|
: private empty_value<Allocator>
|
| 45 |
|
|
45 |
|
|
| 46 |
|
template<class U, class OtherAlloc>
|
46 |
|
template<class U, class OtherAlloc>
|
| 47 |
|
friend class over_allocator;
|
47 |
|
friend class over_allocator;
|
| 48 |
|
|
48 |
|
|
| 49 |
|
|
49 |
|
|
| 50 |
|
|
50 |
|
|
| 51 |
|
|
51 |
|
|
| 52 |
|
using is_always_equal = std::false_type;
|
52 |
|
using is_always_equal = std::false_type;
|
| 53 |
|
using value_type = typename
|
53 |
|
using value_type = typename
|
| 54 |
|
allocator_traits<typename allocator_traits<
|
54 |
|
allocator_traits<typename allocator_traits<
|
| 55 |
|
Allocator>::template rebind_alloc<T>>::value_type;
|
55 |
|
Allocator>::template rebind_alloc<T>>::value_type;
|
| 56 |
|
|
56 |
|
|
| 57 |
|
allocator_traits<typename allocator_traits<
|
57 |
|
allocator_traits<typename allocator_traits<
|
| 58 |
|
Allocator>::template rebind_alloc<T>>::pointer;
|
58 |
|
Allocator>::template rebind_alloc<T>>::pointer;
|
| 59 |
|
using const_pointer = typename
|
59 |
|
using const_pointer = typename
|
| 60 |
|
allocator_traits<typename allocator_traits<
|
60 |
|
allocator_traits<typename allocator_traits<
|
| 61 |
|
Allocator>::template rebind_alloc<T>>::const_pointer;
|
61 |
|
Allocator>::template rebind_alloc<T>>::const_pointer;
|
| 62 |
|
using size_type = typename
|
62 |
|
using size_type = typename
|
| 63 |
|
allocator_traits<typename allocator_traits<
|
63 |
|
allocator_traits<typename allocator_traits<
|
| 64 |
|
Allocator>::template rebind_alloc<T>>::size_type;
|
64 |
|
Allocator>::template rebind_alloc<T>>::size_type;
|
| 65 |
|
using difference_type = typename
|
65 |
|
using difference_type = typename
|
| 66 |
|
allocator_traits<typename allocator_traits<
|
66 |
|
allocator_traits<typename allocator_traits<
|
| 67 |
|
Allocator>::template rebind_alloc<T>>::difference_type;
|
67 |
|
Allocator>::template rebind_alloc<T>>::difference_type;
|
| 68 |
|
|
68 |
|
|
| 69 |
|
|
69 |
|
|
| 70 |
|
|
70 |
|
|
| 71 |
|
|
71 |
|
|
| 72 |
|
using other = over_allocator<U, Allocator>;
|
72 |
|
using other = over_allocator<U, Allocator>;
|
| 73 |
|
|
73 |
|
|
| 74 |
|
|
74 |
|
|
| 75 |
|
|
75 |
|
|
| 76 |
|
|
76 |
|
|
| 77 |
|
|
77 |
|
|
| 78 |
|
: empty_value<Allocator>(
|
78 |
|
: empty_value<Allocator>(
|
| 79 |
|
|
79 |
|
|
| 80 |
|
|
80 |
|
|
| 81 |
|
|
81 |
|
|
| 82 |
|
|
82 |
|
|
| 83 |
|
|
83 |
|
|
| 84 |
|
|
84 |
|
|
| 85 |
|
over_allocator(over_allocator<U, Allocator> const& other) noexcept
|
85 |
|
over_allocator(over_allocator<U, Allocator> const& other) noexcept
|
| 86 |
|
: empty_value<Allocator>(
|
86 |
|
: empty_value<Allocator>(
|
| 87 |
|
|
87 |
|
|
| 88 |
|
|
88 |
|
|
| 89 |
|
|
89 |
|
|
| 90 |
|
|
90 |
|
|
| 91 |
|
|
91 |
|
|
| 92 |
|
|
92 |
|
|
| 93 |
|
|
93 |
|
|
| 94 |
|
|
94 |
|
|
| 95 |
|
|
95 |
|
|
| 96 |
|
using U = typename boost::type_with_alignment<
|
96 |
|
using U = typename boost::type_with_alignment<
|
| 97 |
|
alignof(value_type)>::type;
|
97 |
|
alignof(value_type)>::type;
|
| 98 |
|
auto constexpr S = sizeof(U);
|
98 |
|
auto constexpr S = sizeof(U);
|
| 99 |
|
using A = typename allocator_traits<
|
99 |
|
using A = typename allocator_traits<
|
| 100 |
|
Allocator>::template rebind_alloc<U>;
|
100 |
|
Allocator>::template rebind_alloc<U>;
|
| 101 |
|
|
101 |
|
|
| 102 |
|
return reinterpret_cast<pointer>(
|
102 |
|
return reinterpret_cast<pointer>(
|
| 103 |
|
std::allocator_traits<A>::allocate(a,
|
103 |
|
std::allocator_traits<A>::allocate(a,
|
| 104 |
|
(n * sizeof(value_type) + extra_ + S - 1) / S));
|
104 |
|
(n * sizeof(value_type) + extra_ + S - 1) / S));
|
| 105 |
|
|
105 |
|
|
| 106 |
|
|
106 |
|
|
| 107 |
|
|
107 |
|
|
| 108 |
|
deallocate(pointer p, size_type n)
|
108 |
|
deallocate(pointer p, size_type n)
|
| 109 |
|
|
109 |
|
|
| 110 |
|
|
110 |
|
|
| 111 |
|
using U = typename boost::type_with_alignment<
|
111 |
|
using U = typename boost::type_with_alignment<
|
| 112 |
|
alignof(value_type)>::type;
|
112 |
|
alignof(value_type)>::type;
|
| 113 |
|
auto constexpr S = sizeof(U);
|
113 |
|
auto constexpr S = sizeof(U);
|
| 114 |
|
using A = typename allocator_traits<
|
114 |
|
using A = typename allocator_traits<
|
| 115 |
|
Allocator>::template rebind_alloc<U>;
|
115 |
|
Allocator>::template rebind_alloc<U>;
|
| 116 |
|
|
116 |
|
|
| 117 |
|
std::allocator_traits<A>::deallocate(a,
|
117 |
|
std::allocator_traits<A>::deallocate(a,
|
| 118 |
|
|
118 |
|
|
| 119 |
|
(n * sizeof(value_type) + extra_ + S - 1) / S);
|
119 |
|
(n * sizeof(value_type) + extra_ + S - 1) / S);
|
| 120 |
|
|
120 |
|
|
| 121 |
|
|
121 |
|
|
| 122 |
|
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000
|
122 |
|
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000
|
| 123 |
|
template<class U, class... Args>
|
123 |
|
template<class U, class... Args>
|
| 124 |
|
|
124 |
|
|
| 125 |
|
construct(U* ptr, Args&&... args)
|
125 |
|
construct(U* ptr, Args&&... args)
|
| 126 |
|
|
126 |
|
|
| 127 |
|
::new((void*)ptr) U(std::forward<Args>(args)...);
|
127 |
|
::new((void*)ptr) U(std::forward<Args>(args)...);
|
| 128 |
|
|
128 |
|
|
| 129 |
|
|
129 |
|
|
| 130 |
|
|
130 |
|
|
| 131 |
|
|
131 |
|
|
| 132 |
|
|
132 |
|
|
| 133 |
|
|
133 |
|
|
| 134 |
|
|
134 |
|
|
| 135 |
|
|
135 |
|
|
| 136 |
|
|
136 |
|
|
| 137 |
|
|
137 |
|
|
| 138 |
|
|
138 |
|
|
| 139 |
|
|
139 |
|
|
| 140 |
|
|
140 |
|
|
| 141 |
|
|
141 |
|
|
| 142 |
|
over_allocator const& lhs,
|
142 |
|
over_allocator const& lhs,
|
| 143 |
|
over_allocator<U, Allocator> const& rhs)
|
143 |
|
over_allocator<U, Allocator> const& rhs)
|
| 144 |
|
|
144 |
|
|
| 145 |
|
|
145 |
|
|
| 146 |
|
lhs.get() == rhs.get() &&
|
146 |
|
lhs.get() == rhs.get() &&
|
| 147 |
|
lhs.extra_ == rhs.extra_;
|
147 |
|
lhs.extra_ == rhs.extra_;
|
| 148 |
|
|
148 |
|
|
| 149 |
|
|
149 |
|
|
| 150 |
|
|
150 |
|
|
| 151 |
|
|
151 |
|
|
| 152 |
|
|
152 |
|
|
| 153 |
|
|
153 |
|
|
| 154 |
|
over_allocator const& lhs,
|
154 |
|
over_allocator const& lhs,
|
| 155 |
|
over_allocator<U, Allocator> const& rhs)
|
155 |
|
over_allocator<U, Allocator> const& rhs)
|
| 156 |
|
|
156 |
|
|
| 157 |
|
|
157 |
|
|
| 158 |
|
|
158 |
|
|
| 159 |
|
|
159 |
|
|
| 160 |
|
|
160 |
|
|
| 161 |
|
|
161 |
|
|
| 162 |
|
|
162 |
|
|
| 163 |
|
|
163 |
|
|
| 164 |
|
|
164 |
|
|
| 165 |
|
|
165 |
|
|