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 #ifndef LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H 10 #define LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H 11 12 #if TEST_STD_VER > 17 13 14 class BooleanTestable { 15 public: 16 constexpr operator bool() const { 17 return value_; 18 } 19 20 friend constexpr BooleanTestable operator==(const BooleanTestable& lhs, const BooleanTestable& rhs) { 21 return lhs.value_ == rhs.value_; 22 } 23 24 friend constexpr BooleanTestable operator!=(const BooleanTestable& lhs, const BooleanTestable& rhs) { 25 return !(lhs == rhs); 26 } 27 28 constexpr BooleanTestable operator!() { 29 return BooleanTestable{!value_}; 30 } 31 32 // this class should behave like a bool, so the constructor shouldn't be explicit 33 constexpr BooleanTestable(bool value) : value_{value} {} 34 constexpr BooleanTestable(const BooleanTestable&) = delete; 35 constexpr BooleanTestable(BooleanTestable&&) = delete; 36 37 private: 38 bool value_; 39 }; 40 41 template <class T> 42 class StrictComparable { 43 public: 44 // this shouldn't be explicit to make it easier to initlaize inside arrays (which it almost always is) 45 constexpr StrictComparable(T value) : value_{value} {} 46 47 friend constexpr BooleanTestable operator==(const StrictComparable& lhs, const StrictComparable& rhs) { 48 return (lhs.value_ == rhs.value_); 49 } 50 51 friend constexpr BooleanTestable operator!=(const StrictComparable& lhs, const StrictComparable& rhs) { 52 return !(lhs == rhs); 53 } 54 55 private: 56 T value_; 57 }; 58 59 #endif // TEST_STD_VER > 17 60 61 #endif // LIBCXX_TEST_SUPPORT_BOOLEAN_TESTABLE_H 62