From ed590b7ac89dcc4dced9c81e64bbd10985d148ec Mon Sep 17 00:00:00 2001 From: skypjack Date: Fri, 6 Feb 2026 18:33:57 +0100 Subject: [PATCH] concepts: allocator_like --- src/entt/core/concepts.hpp | 11 +++++++++++ test/entt/core/concepts.cpp | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/entt/core/concepts.hpp b/src/entt/core/concepts.hpp index 652a732f8..63427d9b8 100644 --- a/src/entt/core/concepts.hpp +++ b/src/entt/core/concepts.hpp @@ -1,6 +1,7 @@ #ifndef ENTT_CORE_CONCEPTS_HPP #define ENTT_CORE_CONCEPTS_HPP +#include #include namespace entt { @@ -12,6 +13,16 @@ namespace entt { template concept cvref_unqualified = std::is_same_v, Type>; +/** + * @brief Specifies that a type is likely an allocator type. + * @tparam Type Type to check. + */ +template +concept allocator_like = requires(Type alloc, typename Type::value_type *value) { + { alloc.allocate(0) } -> std::same_as; + { alloc.deallocate(value, 0) } -> std::same_as; +}; + } // namespace entt #endif diff --git a/test/entt/core/concepts.cpp b/test/entt/core/concepts.cpp index 545187c09..d66f25401 100644 --- a/test/entt/core/concepts.cpp +++ b/test/entt/core/concepts.cpp @@ -12,3 +12,10 @@ TEST(Concepts, CVRefUnqualified) { ASSERT_FALSE(entt::cvref_unqualified>); ASSERT_FALSE(entt::cvref_unqualified &>); } + +TEST(Concepts, AllocatorLike) { + ASSERT_FALSE(entt::allocator_like); + ASSERT_TRUE(entt::allocator_like>); + ASSERT_TRUE(entt::allocator_like>); + ASSERT_FALSE(entt::allocator_like>); +}