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
No known key found for this signature in database
GPG key ID: DE48307B8B0D381A
6 changed files with 191 additions and 74 deletions

View file

@ -8,36 +8,7 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/internal/catch_compare_traits.hpp>
// Should only be constructible from literal 0.
// Used by `TypeWithLit0Comparisons` for testing comparison
// ops that only work with literal zero, the way std::*orderings do
struct ZeroLiteralDetector {
constexpr ZeroLiteralDetector( ZeroLiteralDetector* ) noexcept {}
template <typename T,
typename = std::enable_if_t<!std::is_same<T, int>::value>>
constexpr ZeroLiteralDetector( T ) = delete;
};
struct TypeWithLit0Comparisons {
#define DEFINE_COMP_OP( op ) \
friend bool operator op( TypeWithLit0Comparisons, ZeroLiteralDetector ) { \
return true; \
} \
friend bool operator op( ZeroLiteralDetector, TypeWithLit0Comparisons ) { \
return false; \
}
DEFINE_COMP_OP( < )
DEFINE_COMP_OP( <= )
DEFINE_COMP_OP( > )
DEFINE_COMP_OP( >= )
DEFINE_COMP_OP( == )
DEFINE_COMP_OP( != )
#undef DEFINE_COMP_OP
};
#include <helpers/type_with_lit_0_comparisons.hpp>
#define ADD_TRAIT_TEST_CASE( op ) \