/** * @file libpmr/allocator.h * @author mutouyun (orz@orzz.org) * @brief A generic polymorphic memory allocator. * @date 2022-11-13 */ #pragma once #include #include "libimp/export.h" #include "libpmr/def.h" #include "libpmr/memory_resource.h" LIBPMR_NAMESPACE_BEG_ namespace detail { /// @brief Helper trait for allocator. template struct has_allocate : std::false_type {}; template struct has_allocate().allocate(std::declval())), void * >::value>::type> : std::true_type {}; template struct has_deallocate : std::false_type {}; template struct has_deallocate().deallocate(std::declval(), std::declval())) > : std::true_type {}; template using is_memory_resource = typename std::enable_if::value && has_deallocate::value>::type; } // namespace detail /** * @brief An allocator which exhibits different allocation behavior * depending upon the memory resource from which it is constructed. * * @remarks Unlike std::pmr::polymorphic_allocator, it does not * rely on a specific inheritance relationship and only restricts * the interface behavior of the incoming memory resource object to * conform to std::pmr::memory_resource. * * @see https://en.cppreference.com/w/cpp/memory/memory_resource * https://en.cppreference.com/w/cpp/memory/polymorphic_allocator */ class LIBIMP_EXPORT allocator { }; LIBPMR_NAMESPACE_END_