1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed
11 // UNSUPPORTED: availability-pmr-missing
12 
13 // <memory_resource>
14 
15 // class monotonic_buffer_resource
16 
17 #include <memory_resource>
18 #include <cassert>
19 #include <cstddef> // size_t
20 
21 struct assert_on_compare : public std::pmr::memory_resource {
do_allocateassert_on_compare22   void* do_allocate(std::size_t, size_t) override {
23     assert(false);
24     return nullptr;
25   }
26 
do_deallocateassert_on_compare27   void do_deallocate(void*, std::size_t, size_t) override { assert(false); }
28 
do_is_equalassert_on_compare29   bool do_is_equal(const std::pmr::memory_resource&) const noexcept override {
30     assert(false);
31     return true;
32   }
33 };
34 
main(int,char **)35 int main(int, char**) {
36   // Same object
37   {
38     std::pmr::monotonic_buffer_resource r1;
39     std::pmr::monotonic_buffer_resource r2;
40     assert(r1 == r1);
41     assert(r1 != r2);
42 
43     std::pmr::memory_resource& p1 = r1;
44     std::pmr::memory_resource& p2 = r2;
45     assert(p1 == p1);
46     assert(p1 != p2);
47     assert(p1 == r1);
48     assert(r1 == p1);
49     assert(p1 != r2);
50     assert(r2 != p1);
51   }
52   // Different types
53   {
54     std::pmr::monotonic_buffer_resource mono1;
55     std::pmr::memory_resource& r1 = mono1;
56     assert_on_compare c;
57     std::pmr::memory_resource& r2 = c;
58     assert(r1 != r2);
59     assert(!(r1 == r2));
60   }
61 
62   return 0;
63 }
64