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