Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / support / boolean_testable.h
blobe810e4e0461dc69c4afd8969d2d744a906d0f7c7
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 //===----------------------------------------------------------------------===//
9 #ifndef LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H
10 #define LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H
12 #include "test_macros.h"
14 #if TEST_STD_VER > 17
16 class BooleanTestable {
17 public:
18 constexpr operator bool() const {
19 return value_;
22 friend constexpr BooleanTestable operator==(const BooleanTestable& lhs, const BooleanTestable& rhs) {
23 return lhs.value_ == rhs.value_;
26 friend constexpr BooleanTestable operator!=(const BooleanTestable& lhs, const BooleanTestable& rhs) {
27 return !(lhs == rhs);
30 constexpr BooleanTestable operator!() {
31 return BooleanTestable{!value_};
34 // this class should behave like a bool, so the constructor shouldn't be explicit
35 constexpr BooleanTestable(bool value) : value_{value} {}
36 constexpr BooleanTestable(const BooleanTestable&) = delete;
37 constexpr BooleanTestable(BooleanTestable&&) = delete;
39 private:
40 bool value_;
43 template <class T>
44 class StrictComparable {
45 public:
46 // this shouldn't be explicit to make it easier to initlaize inside arrays (which it almost always is)
47 constexpr StrictComparable(T value) : value_{value} {}
49 friend constexpr BooleanTestable operator==(const StrictComparable& lhs, const StrictComparable& rhs) {
50 return (lhs.value_ == rhs.value_);
53 friend constexpr BooleanTestable operator!=(const StrictComparable& lhs, const StrictComparable& rhs) {
54 return !(lhs == rhs);
57 private:
58 T value_;
61 #endif // TEST_STD_VER > 17
63 #endif // LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H