| 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 |
| 10 | |
| 11 | // <propagate_const> |
| 12 | |
| 13 | // template <class T> constexpr bool operator==(const propagate_const<T>& x, const propagate_const<T>& y); |
| 14 | // template <class T> constexpr bool operator==(const T& x, const propagate_const<T>& y); |
| 15 | // template <class T> constexpr bool operator==(const propagate_const<T>& x, const T& y); |
| 16 | |
| 17 | #include <experimental/propagate_const> |
| 18 | #include <cassert> |
| 19 | #include <cstddef> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "propagate_const_helpers.h" |
| 23 | |
| 24 | using std::experimental::propagate_const; |
| 25 | using std::nullptr_t; |
| 26 | |
| 27 | constexpr bool operator==(const X &lhs, const X &rhs) { |
| 28 | return lhs.i_ == rhs.i_; |
| 29 | } |
| 30 | |
| 31 | constexpr bool operator==(const X &, const nullptr_t &) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | constexpr bool operator==(const nullptr_t &, const X &) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | int main(int, char**) { |
| 40 | constexpr X x1_1(1); |
| 41 | constexpr X x2_1(1); |
| 42 | constexpr X x3_2(2); |
| 43 | |
| 44 | static_assert(x1_1 == x1_1, "" ); |
| 45 | static_assert(x1_1 == x2_1, "" ); |
| 46 | static_assert(!(x1_1 == x3_2), "" ); |
| 47 | |
| 48 | typedef propagate_const<X> P; |
| 49 | |
| 50 | constexpr P p1_1(1); |
| 51 | constexpr P p2_1(1); |
| 52 | constexpr P p3_2(2); |
| 53 | |
| 54 | static_assert(p1_1 == p1_1, "" ); |
| 55 | static_assert(p1_1 == p2_1, "" ); |
| 56 | static_assert(!(p1_1 == p3_2), "" ); |
| 57 | |
| 58 | static_assert(x1_1 == p1_1, "" ); |
| 59 | static_assert(!(x1_1 == p3_2), "" ); |
| 60 | |
| 61 | static_assert(p1_1 == x1_1, "" ); |
| 62 | static_assert(!(p1_1 == x3_2), "" ); |
| 63 | |
| 64 | static_assert(!(p1_1==nullptr),"" ); |
| 65 | static_assert(!(nullptr==p1_1),"" ); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |