Skip to content

Commit f93d289

Browse files
committed
entt: there is a reason why an allocator concept does not exist...
1 parent 106af0f commit f93d289

File tree

27 files changed

+88
-115
lines changed

27 files changed

+88
-115
lines changed

src/entt/container/dense_map.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "../config/config.h"
1818
#include "../core/bit.hpp"
1919
#include "../core/compressed_pair.hpp"
20-
#include "../core/concepts.hpp"
2120
#include "../core/iterator.hpp"
2221
#include "../core/memory.hpp"
2322
#include "../core/type_traits.hpp"
@@ -40,16 +39,18 @@ struct dense_map_node final {
4039
: next{pos},
4140
element{std::forward<Args>(args)...} {}
4241

43-
template<typename... Args>
44-
dense_map_node(std::allocator_arg_t, const allocator_like auto &allocator, const std::size_t pos, Args &&...args)
42+
template<typename Allocator, typename... Args>
43+
dense_map_node(std::allocator_arg_t, const Allocator &allocator, const std::size_t pos, Args &&...args)
4544
: next{pos},
4645
element{entt::make_obj_using_allocator<value_type>(allocator, std::forward<Args>(args)...)} {}
4746

48-
dense_map_node(std::allocator_arg_t, const allocator_like auto &allocator, const dense_map_node &other)
47+
template<typename Allocator>
48+
dense_map_node(std::allocator_arg_t, const Allocator &allocator, const dense_map_node &other)
4949
: next{other.next},
5050
element{entt::make_obj_using_allocator<value_type>(allocator, other.element)} {}
5151

52-
dense_map_node(std::allocator_arg_t, const allocator_like auto &allocator, dense_map_node &&other)
52+
template<typename Allocator>
53+
dense_map_node(std::allocator_arg_t, const Allocator &allocator, dense_map_node &&other)
5354
: next{other.next},
5455
element{entt::make_obj_using_allocator<value_type>(allocator, std::move(other.element))} {}
5556

@@ -227,8 +228,9 @@ class dense_map_local_iterator final {
227228
* @tparam Type Mapped type of the associative container.
228229
* @tparam Hash Type of function to use to hash the keys.
229230
* @tparam KeyEqual Type of function to use to compare the keys for equality.
231+
* @tparam Allocator Type of allocator used to manage memory and elements.
230232
*/
231-
template<typename Key, typename Type, typename Hash, typename KeyEqual, allocator_like Allocator>
233+
template<typename Key, typename Type, typename Hash, typename KeyEqual, typename Allocator>
232234
class dense_map {
233235
static constexpr float default_threshold = 0.875f;
234236
static constexpr std::size_t minimum_capacity = 8u;
@@ -1015,7 +1017,7 @@ class dense_map {
10151017
/*! @cond ENTT_INTERNAL */
10161018
namespace std {
10171019

1018-
template<typename Key, typename Value, entt::allocator_like Allocator>
1020+
template<typename Key, typename Value, typename Allocator>
10191021
struct uses_allocator<entt::internal::dense_map_node<Key, Value>, Allocator>
10201022
: std::true_type {};
10211023

src/entt/container/dense_set.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ class dense_set_local_iterator final {
190190
* @tparam Type Value type of the associative container.
191191
* @tparam Hash Type of function to use to hash the values.
192192
* @tparam KeyEqual Type of function to use to compare the values for equality.
193+
* @tparam Allocator Type of allocator used to manage memory and elements.
193194
*/
194-
template<typename Type, typename Hash, typename KeyEqual, allocator_like Allocator>
195+
template<typename Type, typename Hash, typename KeyEqual, typename Allocator>
195196
class dense_set {
196197
static constexpr float default_threshold = 0.875f;
197198
static constexpr std::size_t minimum_capacity = 8u;

src/entt/container/fwd.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <memory>
66
#include <utility>
77
#include <vector>
8-
#include "../core/concepts.hpp"
98

109
namespace entt {
1110

@@ -14,14 +13,14 @@ template<
1413
typename Type,
1514
typename = std::hash<Key>,
1615
typename = std::equal_to<>,
17-
allocator_like = std::allocator<std::pair<const Key, Type>>>
16+
typename = std::allocator<std::pair<const Key, Type>>>
1817
class dense_map;
1918

2019
template<
2120
typename Type,
2221
typename = std::hash<Type>,
2322
typename = std::equal_to<>,
24-
allocator_like = std::allocator<Type>>
23+
typename = std::allocator<Type>>
2524
class dense_set;
2625

2726
template<typename...>

src/entt/container/table.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ class basic_table {
170170

171171
/**
172172
* @brief Constructs the underlying containers using a given allocator.
173+
* @tparam Allocator Type of allocator.
173174
* @param allocator A valid allocator.
174175
*/
175-
explicit basic_table(const allocator_like auto &allocator)
176+
template<typename Allocator>
177+
explicit basic_table(const Allocator &allocator)
176178
: payload{Container{allocator}...} {}
177179

178180
/**
@@ -422,7 +424,7 @@ class basic_table {
422424
/*! @cond ENTT_INTERNAL */
423425
namespace std {
424426

425-
template<typename... Container, entt::allocator_like Allocator>
427+
template<typename... Container, typename Allocator>
426428
struct uses_allocator<entt::basic_table<Container...>, Allocator>
427429
: std::bool_constant<(std::uses_allocator_v<Container, Allocator> && ...)> {};
428430

src/entt/core/concepts.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef ENTT_CORE_CONCEPTS_HPP
22
#define ENTT_CORE_CONCEPTS_HPP
33

4-
#include <concepts>
54
#include <type_traits>
65

76
namespace entt {
@@ -13,16 +12,6 @@ namespace entt {
1312
template<typename Type>
1413
concept cvref_unqualified = std::is_same_v<std::remove_cvref_t<Type>, Type>;
1514

16-
/**
17-
* @brief Specifies that a type is likely an allocator type.
18-
* @tparam Type Type to check.
19-
*/
20-
template<typename Type>
21-
concept allocator_like = requires(Type alloc, typename Type::value_type *value) {
22-
{ alloc.allocate(0) } -> std::same_as<decltype(value)>;
23-
{ alloc.deallocate(value, 0) } -> std::same_as<void>;
24-
};
25-
2615
} // namespace entt
2716

2817
#endif

src/entt/core/memory.hpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <type_traits>
88
#include <utility>
99
#include "../config/config.h"
10-
#include "../core/concepts.hpp"
1110
#include "../stl/memory.hpp"
1211

1312
namespace entt {
@@ -18,7 +17,7 @@ namespace entt {
1817
* @param lhs A valid allocator.
1918
* @param rhs Another valid allocator.
2019
*/
21-
template<allocator_like Allocator>
20+
template<typename Allocator>
2221
constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) noexcept {
2322
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {
2423
lhs = rhs;
@@ -31,7 +30,7 @@ constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator
3130
* @param lhs A valid allocator.
3231
* @param rhs Another valid allocator.
3332
*/
34-
template<allocator_like Allocator>
33+
template<typename Allocator>
3534
constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) noexcept {
3635
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
3736
lhs = std::move(rhs);
@@ -44,7 +43,7 @@ constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator
4443
* @param lhs A valid allocator.
4544
* @param rhs Another valid allocator.
4645
*/
47-
template<allocator_like Allocator>
46+
template<typename Allocator>
4847
constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) noexcept {
4948
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_swap::value) {
5049
using std::swap;
@@ -58,7 +57,7 @@ constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[ma
5857
* @brief Deleter for allocator-aware unique pointers (waiting for C++20).
5958
* @tparam Allocator Type of allocator used to manage memory and elements.
6059
*/
61-
template<allocator_like Allocator>
60+
template<typename Allocator>
6261
struct allocation_deleter: private Allocator {
6362
/*! @brief Allocator type. */
6463
using allocator_type = Allocator;
@@ -92,7 +91,7 @@ struct allocation_deleter: private Allocator {
9291
* @param args Parameters to use to construct the object.
9392
* @return A properly initialized unique pointer with a custom deleter.
9493
*/
95-
template<typename Type, allocator_like Allocator, typename... Args>
94+
template<typename Type, typename Allocator, typename... Args>
9695
constexpr auto allocate_unique(Allocator &allocator, Args &&...args) {
9796
static_assert(!std::is_array_v<Type>, "Array types are not supported");
9897

@@ -118,7 +117,7 @@ namespace internal {
118117

119118
template<typename Type>
120119
struct uses_allocator_construction {
121-
template<allocator_like Allocator, typename... Params>
120+
template<typename Allocator, typename... Params>
122121
static constexpr auto args([[maybe_unused]] const Allocator &allocator, Params &&...params) noexcept {
123122
if constexpr(!std::uses_allocator_v<Type, Allocator> && std::is_constructible_v<Type, Params...>) {
124123
return std::forward_as_tuple(std::forward<Params>(params)...);
@@ -139,30 +138,31 @@ template<typename Type, typename Other>
139138
struct uses_allocator_construction<std::pair<Type, Other>> {
140139
using type = std::pair<Type, Other>;
141140

142-
template<typename First, typename Second>
143-
static constexpr auto args(const allocator_like auto &allocator, std::piecewise_construct_t, First &&first, Second &&second) noexcept {
141+
template<typename Allocator, typename First, typename Second>
142+
static constexpr auto args(const Allocator &allocator, std::piecewise_construct_t, First &&first, Second &&second) noexcept {
144143
return std::make_tuple(
145144
std::piecewise_construct,
146145
std::apply([&allocator](auto &&...curr) { return uses_allocator_construction<Type>::args(allocator, std::forward<decltype(curr)>(curr)...); }, std::forward<First>(first)),
147146
std::apply([&allocator](auto &&...curr) { return uses_allocator_construction<Other>::args(allocator, std::forward<decltype(curr)>(curr)...); }, std::forward<Second>(second)));
148147
}
149148

150-
static constexpr auto args(const allocator_like auto &allocator) noexcept {
149+
template<typename Allocator>
150+
static constexpr auto args(const Allocator &allocator) noexcept {
151151
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::tuple<>{}, std::tuple<>{});
152152
}
153153

154-
template<typename First, typename Second>
155-
static constexpr auto args(const allocator_like auto &allocator, First &&first, Second &&second) noexcept {
154+
template<typename Allocator, typename First, typename Second>
155+
static constexpr auto args(const Allocator &allocator, First &&first, Second &&second) noexcept {
156156
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::forward_as_tuple(std::forward<First>(first)), std::forward_as_tuple(std::forward<Second>(second)));
157157
}
158158

159-
template<typename First, typename Second>
160-
static constexpr auto args(const allocator_like auto &allocator, const std::pair<First, Second> &value) noexcept {
159+
template<typename Allocator, typename First, typename Second>
160+
static constexpr auto args(const Allocator &allocator, const std::pair<First, Second> &value) noexcept {
161161
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::forward_as_tuple(value.first), std::forward_as_tuple(value.second));
162162
}
163163

164-
template<typename First, typename Second>
165-
static constexpr auto args(const allocator_like auto &allocator, std::pair<First, Second> &&value) noexcept {
164+
template<typename Allocator, typename First, typename Second>
165+
static constexpr auto args(const Allocator &allocator, std::pair<First, Second> &&value) noexcept {
166166
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::forward_as_tuple(std::move(value.first)), std::forward_as_tuple(std::move(value.second)));
167167
}
168168
};
@@ -177,13 +177,14 @@ struct uses_allocator_construction<std::pair<Type, Other>> {
177177
* create an object of a given type by means of uses-allocator construction.
178178
*
179179
* @tparam Type Type to return arguments for.
180+
* @tparam Allocator Type of allocator used to manage memory and elements.
180181
* @tparam Args Types of arguments to use to construct the object.
181182
* @param allocator The allocator to use.
182183
* @param args Parameters to use to construct the object.
183184
* @return The arguments needed to create an object of the given type.
184185
*/
185-
template<typename Type, typename... Args>
186-
constexpr auto uses_allocator_construction_args(const allocator_like auto &allocator, Args &&...args) noexcept {
186+
template<typename Type, typename Allocator, typename... Args>
187+
constexpr auto uses_allocator_construction_args(const Allocator &allocator, Args &&...args) noexcept {
187188
return internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...);
188189
}
189190

@@ -194,13 +195,14 @@ constexpr auto uses_allocator_construction_args(const allocator_like auto &alloc
194195
* means of uses-allocator construction.
195196
*
196197
* @tparam Type Type of object to create.
198+
* @tparam Allocator Type of allocator used to manage memory and elements.
197199
* @tparam Args Types of arguments to use to construct the object.
198200
* @param allocator The allocator to use.
199201
* @param args Parameters to use to construct the object.
200202
* @return A newly created object of the given type.
201203
*/
202-
template<typename Type, typename... Args>
203-
constexpr Type make_obj_using_allocator(const allocator_like auto &allocator, Args &&...args) {
204+
template<typename Type, typename Allocator, typename... Args>
205+
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args) {
204206
return std::make_from_tuple<Type>(internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...));
205207
}
206208

@@ -211,14 +213,15 @@ constexpr Type make_obj_using_allocator(const allocator_like auto &allocator, Ar
211213
* means of uses-allocator construction at an uninitialized memory location.
212214
*
213215
* @tparam Type Type of object to create.
216+
* @tparam Allocator Type of allocator used to manage memory and elements.
214217
* @tparam Args Types of arguments to use to construct the object.
215218
* @param value Memory location in which to place the object.
216219
* @param allocator The allocator to use.
217220
* @param args Parameters to use to construct the object.
218221
* @return A pointer to the newly created object of the given type.
219222
*/
220-
template<typename Type, typename... Args>
221-
constexpr Type *uninitialized_construct_using_allocator(Type *value, const allocator_like auto &allocator, Args &&...args) {
223+
template<typename Type, typename Allocator, typename... Args>
224+
constexpr Type *uninitialized_construct_using_allocator(Type *value, const Allocator &allocator, Args &&...args) {
222225
return std::apply([value](auto &&...curr) { return ::new(value) Type(std::forward<decltype(curr)>(curr)...); }, internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...));
223226
}
224227

src/entt/entity/fwd.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ enum class deletion_policy : std::uint8_t {
4747
template<cvref_unqualified Type, entity_like Entity = entity>
4848
struct component_traits;
4949

50-
template<entity_like Entity = entity, allocator_like = std::allocator<Entity>>
50+
template<entity_like Entity = entity, typename = std::allocator<Entity>>
5151
class basic_sparse_set;
5252

53-
template<typename Type, entity_like = entity, allocator_like = std::allocator<Type>>
53+
template<typename Type, entity_like = entity, typename = std::allocator<Type>>
5454
class basic_storage;
5555

5656
template<typename, typename>
@@ -59,13 +59,13 @@ class basic_sigh_mixin;
5959
template<typename, typename>
6060
class basic_reactive_mixin;
6161

62-
template<entity_like Entity = entity, allocator_like = std::allocator<Entity>>
62+
template<entity_like Entity = entity, typename = std::allocator<Entity>>
6363
class basic_registry;
6464

6565
template<typename, typename>
6666
class basic_view;
6767

68-
template<typename Type, allocator_like = std::allocator<Type *>>
68+
template<typename Type, typename = std::allocator<Type *>>
6969
class basic_runtime_view;
7070

7171
template<typename, typename, typename>
@@ -241,7 +241,7 @@ struct type_list_transform<owned_t<Type...>, Op> {
241241
* @tparam Entity A valid entity type.
242242
* @tparam Allocator Type of allocator used to manage memory and elements.
243243
*/
244-
template<typename Type, entity_like Entity = entity, allocator_like Allocator = std::allocator<Type>>
244+
template<typename Type, entity_like Entity = entity, typename Allocator = std::allocator<Type>>
245245
struct storage_type {
246246
/*! @brief Type-to-storage conversion result. */
247247
using type = ENTT_STORAGE(sigh_mixin, basic_storage<Type, Entity, Allocator>);
@@ -255,7 +255,7 @@ struct reactive final {};
255255
* @tparam Entity A valid entity type.
256256
* @tparam Allocator Type of allocator used to manage memory and elements.
257257
*/
258-
template<entity_like Entity, allocator_like Allocator>
258+
template<entity_like Entity, typename Allocator>
259259
struct storage_type<reactive, Entity, Allocator> {
260260
/*! @brief Type-to-storage conversion result. */
261261
using type = ENTT_STORAGE(reactive_mixin, basic_storage<reactive, Entity, Allocator>);
@@ -274,7 +274,7 @@ using storage_type_t = storage_type<Args...>::type;
274274
* @tparam Entity A valid entity type.
275275
* @tparam Allocator Type of allocator used to manage memory and elements.
276276
*/
277-
template<typename Type, entity_like Entity = entity, allocator_like Allocator = std::allocator<std::remove_const_t<Type>>>
277+
template<typename Type, entity_like Entity = entity, typename Allocator = std::allocator<std::remove_const_t<Type>>>
278278
struct storage_for {
279279
/*! @brief Type-to-storage conversion result. */
280280
using type = constness_as_t<storage_type_t<std::remove_const_t<Type>, Entity, Allocator>, Type>;

src/entt/entity/group.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <utility>
1111
#include "../config/config.h"
1212
#include "../core/algorithm.hpp"
13-
#include "../core/concepts.hpp"
1413
#include "../core/fwd.hpp"
1514
#include "../core/iterator.hpp"
1615
#include "../core/type_info.hpp"
@@ -206,8 +205,8 @@ class group_handler<Type, 0u, Get, Exclude> final: public group_descriptor {
206205
public:
207206
using common_type = Type;
208207

209-
template<typename... GType, typename... EType>
210-
group_handler(const allocator_like auto &allocator, std::tuple<GType &...> gpool, std::tuple<EType &...> epool)
208+
template<typename Allocator, typename... GType, typename... EType>
209+
group_handler(const Allocator &allocator, std::tuple<GType &...> gpool, std::tuple<EType &...> epool)
211210
: pools{std::apply([](auto &&...cpool) { return std::array<common_type *, Get>{&cpool...}; }, gpool)},
212211
filter{std::apply([](auto &&...cpool) { return std::array<common_type *, Exclude>{&cpool...}; }, epool)},
213212
elem{allocator} {

src/entt/entity/registry.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class registry_storage_iterator final {
131131
It it;
132132
};
133133

134-
template<allocator_like Allocator>
134+
template<typename Allocator>
135135
class registry_context {
136136
using alloc_traits = std::allocator_traits<Allocator>;
137137
using allocator_type = alloc_traits::template rebind_alloc<std::pair<const id_type, basic_any<0u>>>;
@@ -210,7 +210,7 @@ class registry_context {
210210
* @tparam Entity A valid entity type.
211211
* @tparam Allocator Type of allocator used to manage memory and elements.
212212
*/
213-
template<entity_like Entity, allocator_like Allocator>
213+
template<entity_like Entity, typename Allocator>
214214
class basic_registry {
215215
using base_type = basic_sparse_set<Entity, Allocator>;
216216
using alloc_traits = std::allocator_traits<Allocator>;

src/entt/entity/runtime_view.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <iterator>
77
#include <utility>
88
#include <vector>
9-
#include "../core/concepts.hpp"
109
#include "entity.hpp"
1110
#include "fwd.hpp"
1211

@@ -116,7 +115,7 @@ class runtime_view_iterator final {
116115
* @tparam Type Common base type.
117116
* @tparam Allocator Type of allocator used to manage memory and elements.
118117
*/
119-
template<typename Type, allocator_like Allocator>
118+
template<typename Type, typename Allocator>
120119
class basic_runtime_view {
121120
using alloc_traits = std::allocator_traits<Allocator>;
122121
static_assert(std::is_same_v<typename alloc_traits::value_type, Type *>, "Invalid value type");

0 commit comments

Comments
 (0)