Support decomposing types that only compare with literal 0

This is primarily done to support new `std::*_ordering` types,
but the refactoring also supports any other type with this
property.

The compilation overhead is surprisingly low. Testing it with
clang on a Linux machine, compiling our SelfTest project takes
only 2-3% longer with these changes than it takes otherwise.

Closes #2555
This commit is contained in:
Martin Hořeňovský
2022-11-01 15:01:43 +01:00
parent d7f8c36e4c
commit ec59cd8736
6 changed files with 191 additions and 74 deletions

View File

@@ -6,6 +6,8 @@
// SPDX-License-Identifier: BSL-1.0
#include <helpers/type_with_lit_0_comparisons.hpp>
#include <type_traits>
// Setup for #1403 -- look for global overloads of operator << for classes
@@ -310,3 +312,20 @@ TEST_CASE("ADL universal operators don't hijack expression deconstruction", "[co
REQUIRE(0 & adl::always_true{});
REQUIRE(0 ^ adl::always_true{});
}
TEST_CASE( "#2555 - types that can only be compared with 0 literal (not int/long) are supported", "[compilation][approvals]" ) {
REQUIRE( TypeWithLit0Comparisons{} < 0 );
REQUIRE_FALSE( 0 < TypeWithLit0Comparisons{} );
REQUIRE( TypeWithLit0Comparisons{} <= 0 );
REQUIRE_FALSE( 0 > TypeWithLit0Comparisons{} );
REQUIRE( TypeWithLit0Comparisons{} > 0 );
REQUIRE_FALSE( 0 > TypeWithLit0Comparisons{} );
REQUIRE( TypeWithLit0Comparisons{} >= 0 );
REQUIRE_FALSE( 0 >= TypeWithLit0Comparisons{} );
REQUIRE( TypeWithLit0Comparisons{} == 0 );
REQUIRE_FALSE( 0 == TypeWithLit0Comparisons{} );
REQUIRE( TypeWithLit0Comparisons{} != 0 );
REQUIRE_FALSE( 0 != TypeWithLit0Comparisons{} );
}