77#include < type_traits>
88#include < utility>
99#include " ../config/config.h"
10+ #include " ../core/concepts.hpp"
1011#include " ../stl/memory.hpp"
1112
1213namespace entt {
@@ -17,7 +18,7 @@ namespace entt {
1718 * @param lhs A valid allocator.
1819 * @param rhs Another valid allocator.
1920 */
20- template <typename Allocator>
21+ template <allocator_like Allocator>
2122constexpr void propagate_on_container_copy_assignment ([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) noexcept {
2223 if constexpr (std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {
2324 lhs = rhs;
@@ -30,7 +31,7 @@ constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator
3031 * @param lhs A valid allocator.
3132 * @param rhs Another valid allocator.
3233 */
33- template <typename Allocator>
34+ template <allocator_like Allocator>
3435constexpr void propagate_on_container_move_assignment ([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) noexcept {
3536 if constexpr (std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
3637 lhs = std::move (rhs);
@@ -43,7 +44,7 @@ constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator
4344 * @param lhs A valid allocator.
4445 * @param rhs Another valid allocator.
4546 */
46- template <typename Allocator>
47+ template <allocator_like Allocator>
4748constexpr void propagate_on_container_swap ([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) noexcept {
4849 if constexpr (std::allocator_traits<Allocator>::propagate_on_container_swap::value) {
4950 using std::swap;
@@ -57,7 +58,7 @@ constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[ma
5758 * @brief Deleter for allocator-aware unique pointers (waiting for C++20).
5859 * @tparam Allocator Type of allocator used to manage memory and elements.
5960 */
60- template <typename Allocator>
61+ template <allocator_like Allocator>
6162struct allocation_deleter : private Allocator {
6263 /* ! @brief Allocator type. */
6364 using allocator_type = Allocator;
@@ -91,7 +92,7 @@ struct allocation_deleter: private Allocator {
9192 * @param args Parameters to use to construct the object.
9293 * @return A properly initialized unique pointer with a custom deleter.
9394 */
94- template <typename Type, typename Allocator, typename ... Args>
95+ template <typename Type, allocator_like Allocator, typename ... Args>
9596constexpr auto allocate_unique (Allocator &allocator, Args &&...args) {
9697 static_assert (!std::is_array_v<Type>, " Array types are not supported" );
9798
@@ -117,7 +118,7 @@ namespace internal {
117118
118119template <typename Type>
119120struct uses_allocator_construction {
120- template <typename Allocator, typename ... Params>
121+ template <allocator_like Allocator, typename ... Params>
121122 static constexpr auto args ([[maybe_unused]] const Allocator &allocator, Params &&...params) noexcept {
122123 if constexpr (!std::uses_allocator_v<Type, Allocator> && std::is_constructible_v<Type, Params...>) {
123124 return std::forward_as_tuple (std::forward<Params>(params)...);
@@ -138,31 +139,30 @@ template<typename Type, typename Other>
138139struct uses_allocator_construction <std::pair<Type, Other>> {
139140 using type = std::pair<Type, Other>;
140141
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 {
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 {
143144 return std::make_tuple (
144145 std::piecewise_construct,
145146 std::apply ([&allocator](auto &&...curr ) { return uses_allocator_construction<Type>::args (allocator, std::forward<decltype (curr)>(curr)...); }, std::forward<First>(first)),
146147 std::apply ([&allocator](auto &&...curr ) { return uses_allocator_construction<Other>::args (allocator, std::forward<decltype (curr)>(curr)...); }, std::forward<Second>(second)));
147148 }
148149
149- template <typename Allocator>
150- static constexpr auto args (const Allocator &allocator) noexcept {
150+ static constexpr auto args (const allocator_like auto &allocator) noexcept {
151151 return uses_allocator_construction<type>::args (allocator, std::piecewise_construct, std::tuple<>{}, std::tuple<>{});
152152 }
153153
154- template <typename Allocator, typename First, typename Second>
155- static constexpr auto args (const Allocator &allocator, First &&first, Second &&second) noexcept {
154+ template <typename First, typename Second>
155+ static constexpr auto args (const allocator_like auto &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 Allocator, typename First, typename Second>
160- static constexpr auto args (const Allocator &allocator, const std::pair<First, Second> &value) noexcept {
159+ template <typename First, typename Second>
160+ static constexpr auto args (const allocator_like auto &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 Allocator, typename First, typename Second>
165- static constexpr auto args (const Allocator &allocator, std::pair<First, Second> &&value) noexcept {
164+ template <typename First, typename Second>
165+ static constexpr auto args (const allocator_like auto &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,14 +177,13 @@ 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.
181180 * @tparam Args Types of arguments to use to construct the object.
182181 * @param allocator The allocator to use.
183182 * @param args Parameters to use to construct the object.
184183 * @return The arguments needed to create an object of the given type.
185184 */
186- template <typename Type, typename Allocator, typename ... Args>
187- constexpr auto uses_allocator_construction_args (const Allocator &allocator, Args &&...args) noexcept {
185+ template <typename Type, typename ... Args>
186+ constexpr auto uses_allocator_construction_args (const allocator_like auto &allocator, Args &&...args) noexcept {
188187 return internal::uses_allocator_construction<Type>::args (allocator, std::forward<Args>(args)...);
189188}
190189
@@ -195,14 +194,13 @@ constexpr auto uses_allocator_construction_args(const Allocator &allocator, Args
195194 * means of uses-allocator construction.
196195 *
197196 * @tparam Type Type of object to create.
198- * @tparam Allocator Type of allocator used to manage memory and elements.
199197 * @tparam Args Types of arguments to use to construct the object.
200198 * @param allocator The allocator to use.
201199 * @param args Parameters to use to construct the object.
202200 * @return A newly created object of the given type.
203201 */
204- template <typename Type, typename Allocator, typename ... Args>
205- constexpr Type make_obj_using_allocator (const Allocator &allocator, Args &&...args) {
202+ template <typename Type, typename ... Args>
203+ constexpr Type make_obj_using_allocator (const allocator_like auto &allocator, Args &&...args) {
206204 return std::make_from_tuple<Type>(internal::uses_allocator_construction<Type>::args (allocator, std::forward<Args>(args)...));
207205}
208206
@@ -213,15 +211,14 @@ constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...ar
213211 * means of uses-allocator construction at an uninitialized memory location.
214212 *
215213 * @tparam Type Type of object to create.
216- * @tparam Allocator Type of allocator used to manage memory and elements.
217214 * @tparam Args Types of arguments to use to construct the object.
218215 * @param value Memory location in which to place the object.
219216 * @param allocator The allocator to use.
220217 * @param args Parameters to use to construct the object.
221218 * @return A pointer to the newly created object of the given type.
222219 */
223- template <typename Type, typename Allocator, typename ... Args>
224- constexpr Type *uninitialized_construct_using_allocator (Type *value, const Allocator &allocator, Args &&...args) {
220+ template <typename Type, typename ... Args>
221+ constexpr Type *uninitialized_construct_using_allocator (Type *value, const allocator_like auto &allocator, Args &&...args) {
225222 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)...));
226223}
227224
0 commit comments