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