add: [pmr] is_memory_resource

This commit is contained in:
mutouyun 2022-11-15 09:30:48 +08:00
parent 4c9c8bb875
commit cc17980b97
2 changed files with 14 additions and 0 deletions

View File

@ -36,6 +36,11 @@ struct has_deallocate<T,
std::declval<std::size_t>())) std::declval<std::size_t>()))
> : std::true_type {}; > : std::true_type {};
template <typename T>
using is_memory_resource =
typename std::enable_if<has_allocate <T>::value &&
has_deallocate<T>::value>::type;
} // namespace detail } // namespace detail
/** /**

View File

@ -17,6 +17,15 @@ TEST(allocator, detail) {
EXPECT_TRUE (pmr::detail::has_allocate<std::pmr::memory_resource>::value); EXPECT_TRUE (pmr::detail::has_allocate<std::pmr::memory_resource>::value);
EXPECT_TRUE (pmr::detail::has_allocate<std::pmr::polymorphic_allocator<int>>::value); EXPECT_TRUE (pmr::detail::has_allocate<std::pmr::polymorphic_allocator<int>>::value);
#endif #endif
EXPECT_FALSE(pmr::detail::has_deallocate<void>::value);
EXPECT_FALSE(pmr::detail::has_deallocate<int>::value);
EXPECT_FALSE(pmr::detail::has_deallocate<std::vector<int>>::value);
EXPECT_FALSE(pmr::detail::has_deallocate<std::allocator<int>>::value);
#if defined(LIBIMP_CPP_17) && defined(__cpp_lib_memory_resource)
EXPECT_TRUE (pmr::detail::has_deallocate<std::pmr::memory_resource>::value);
EXPECT_FALSE(pmr::detail::has_deallocate<std::pmr::polymorphic_allocator<int>>::value);
#endif
} }
TEST(allocator, construct) { TEST(allocator, construct) {