Skip to content

Commit

Permalink
add libc++ compatibility by checking for <experimental/memory_resource>
Browse files Browse the repository at this point in the history
Until LLVM 16 is released, and until Android and Apple platforms
incorporate the forthcoming std::pmr support in their forks of libc++,
this workaround is needed to use pmr containers on those platforms.
  • Loading branch information
justusranvier authored and martinus committed Jan 7, 2023
1 parent db89395 commit 2d8a192
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions include/ankerl/unordered_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@
# if __has_include(<memory_resource>)
# undef ANKERL_UNORDERED_DENSE_PMR
# define ANKERL_UNORDERED_DENSE_PMR 1 // NOLINT(cppcoreguidelines-macro-usage)
# include <memory_resource> // for polymorphic_allocator
# define ANKERL_UNORDERED_DENSE_PMR_ALLOCATOR \
std::pmr::polymorphic_allocator // NOLINT(cppcoreguidelines-macro-usage)
# include <memory_resource> // for polymorphic_allocator
# elif __has_include(<experimental/memory_resource>)
# undef ANKERL_UNORDERED_DENSE_PMR
# define ANKERL_UNORDERED_DENSE_PMR 1 // NOLINT(cppcoreguidelines-macro-usage)
# define ANKERL_UNORDERED_DENSE_PMR_ALLOCATOR \
std::experimental::pmr::polymorphic_allocator // NOLINT(cppcoreguidelines-macro-usage)
# include <experimental/memory_resource> // for polymorphic_allocator
# endif
# endif

Expand Down Expand Up @@ -1483,10 +1491,10 @@ template <class Key,
class Hash = hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Bucket = bucket_type::standard>
using map = detail::table<Key, T, Hash, KeyEqual, std::pmr::polymorphic_allocator<std::pair<Key, T>>, Bucket>;
using map = detail::table<Key, T, Hash, KeyEqual, ANKERL_UNORDERED_DENSE_PMR_ALLOCATOR<std::pair<Key, T>>, Bucket>;

template <class Key, class Hash = hash<Key>, class KeyEqual = std::equal_to<Key>, class Bucket = bucket_type::standard>
using set = detail::table<Key, void, Hash, KeyEqual, std::pmr::polymorphic_allocator<Key>, Bucket>;
using set = detail::table<Key, void, Hash, KeyEqual, ANKERL_UNORDERED_DENSE_PMR_ALLOCATOR<Key>, Bucket>;

} // namespace pmr

Expand Down
2 changes: 2 additions & 0 deletions test/unit/pmr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#if ANKERL_UNORDERED_DENSE_PMR

# if __has_include(<memory_resource>)
# include <memory_resource>

class logging_memory_resource : public std::pmr::memory_resource {
Expand Down Expand Up @@ -220,4 +221,5 @@ TEST_CASE("pmr_move_same_mr") {
}
# endif

# endif
#endif

0 comments on commit 2d8a192

Please sign in to comment.