Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions stl/inc/xpolymorphic_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,18 @@ namespace pmr {
return _Resource;
}

_NODISCARD_FRIEND bool operator==(
Comment thread
StephanTLavavej marked this conversation as resolved.
const polymorphic_allocator& _Lhs, const polymorphic_allocator& _Rhs) noexcept {
return *_Lhs._Resource == *_Rhs._Resource;
}

#if !_HAS_CXX20
_NODISCARD_FRIEND bool operator!=(
const polymorphic_allocator& _Lhs, const polymorphic_allocator& _Rhs) noexcept {
return *_Lhs._Resource != *_Rhs._Resource;
}
#endif // !_HAS_CXX20

private:
memory_resource* _Resource = _STD pmr::get_default_resource();
};
Expand Down
41 changes: 41 additions & 0 deletions tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstdlib>
#include <deque>
#include <forward_list>
#include <functional>
#include <list>
#include <malloc.h>
#include <map>
Expand Down Expand Up @@ -946,6 +947,45 @@ namespace {
}
} // namespace eq

namespace eq_cvt {
void test() {
const auto pres = std::pmr::get_default_resource();
std::pmr::polymorphic_allocator<int> a = pres;
const auto ra = std::ref(a);
const auto cra = std::cref(a);

CHECK(a == pres);
CHECK(a == ra);
CHECK(a == cra);
CHECK(pres == a);
CHECK(pres == ra);
CHECK(pres == cra);
CHECK(ra == a);
CHECK(ra == pres);
CHECK(ra == ra);
CHECK(ra == cra);
CHECK(cra == a);
CHECK(cra == pres);
CHECK(cra == ra);
CHECK(cra == cra);

CHECK(!(a != pres));
CHECK(!(a != ra));
CHECK(!(a != cra));
CHECK(!(pres != a));
CHECK(!(pres != ra));
CHECK(!(pres != cra));
CHECK(!(ra != a));
CHECK(!(ra != pres));
CHECK(!(ra != ra));
CHECK(!(ra != cra));
CHECK(!(cra != a));
CHECK(!(cra != pres));
CHECK(!(cra != ra));
CHECK(!(cra != cra));
}
} // namespace eq_cvt

namespace destroy {
void test() {
bool destroyed = false;
Expand Down Expand Up @@ -1505,6 +1545,7 @@ int main() {
polymorphic_allocator::mem::select_on_container_copy_construction::test();
polymorphic_allocator::mem::resource::test();
polymorphic_allocator::eq::test();
polymorphic_allocator::eq_cvt::test();
polymorphic_allocator::destroy::test();

monotonic::ctor::buffer_upstream::test();
Expand Down