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
10 
11 // <experimental/memory_resource>
12 
13 // bool operator==(memory_resource const &, memory_resource const &) noexcept;
14 
15 #include <experimental/memory_resource>
16 #include <type_traits>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "test_memory_resource.h"
21 
22 namespace ex = std::experimental::pmr;
23 
24 int main(int, char**)
25 {
26     // check return types
27     {
28         ex::memory_resource const * mr1(nullptr);
29         ex::memory_resource const * mr2(nullptr);
30         static_assert(std::is_same<decltype(*mr1 == *mr2), bool>::value, "");
31         static_assert(noexcept(*mr1 == *mr2), "");
destroyabledestroyable32     }
33     // equal
34     {
35         TestResource r1(1);
36         TestResource r2(1);
37         ex::memory_resource const & mr1 = r1;
38         ex::memory_resource const & mr2 = r2;
39 
40         assert(mr1 == mr2);
41         assert(r1.checkIsEqualCalledEq(1));
42         assert(r2.checkIsEqualCalledEq(0));
43 
44         assert(mr2 == mr1);
45         assert(r1.checkIsEqualCalledEq(1));
46         assert(r2.checkIsEqualCalledEq(1));
47     }
48     // equal same object
49     {
50         TestResource r1(1);
51         ex::memory_resource const & mr1 = r1;
52         ex::memory_resource const & mr2 = r1;
53 
54         assert(mr1 == mr2);
55         assert(r1.checkIsEqualCalledEq(0));
56 
57         assert(mr2 == mr1);
58         assert(r1.checkIsEqualCalledEq(0));
59     }
60     // not equal
61     {
62         TestResource r1(1);
63         TestResource r2(2);
64         ex::memory_resource const & mr1 = r1;
65         ex::memory_resource const & mr2 = r2;
66 
67         assert(!(mr1 == mr2));
68         assert(r1.checkIsEqualCalledEq(1));
69         assert(r2.checkIsEqualCalledEq(0));
70 
71         assert(!(mr2 == mr1));
72         assert(r1.checkIsEqualCalledEq(1));
73         assert(r2.checkIsEqualCalledEq(1));
74     }
75 
76   return 0;
77 }
78