1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H
10 #define LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H
12 #include "test_macros.h"
16 class BooleanTestable
{
18 constexpr operator bool() const {
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
) {
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;
44 class StrictComparable
{
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
) {
61 #endif // TEST_STD_VER > 17
63 #endif // LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H