|
SCL Feature 0.0.1
C++20 composable proxy wrapper with pluggable executor strategy
|
Compile-time predicate macro for cv-ref qualifier detection. More...
Go to the source code of this file.
Macros | |
| #define | SCL_HAS_QUALIFIED_METHOD(method, Type, ...) |
Compile-time predicate: checks whether Type has a dedicated overload of method whose cv-ref qualifiers exactly match those of Type. | |
Compile-time predicate macro for cv-ref qualifier detection.
| #define SCL_HAS_QUALIFIED_METHOD | ( | method, | |
| Type, | |||
| ... ) |
Compile-time predicate: checks whether Type has a dedicated overload of method whose cv-ref qualifiers exactly match those of Type.
In C++ a method qualified as const& is implicitly callable on a mutable lvalue, because a mutable reference converts to a const one. A simple requires expression therefore cannot distinguish "the
class has a @c const& overload" from "the class has a mutable @c &
overload that is also callable on @c const&".
This macro solves the problem by comparing return types of calls with different cv-ref qualifiers. If the return types differ, the class must have separate overloads; if they are the same, the call is assumed to go through implicit cv-widening and the predicate returns false.
mutable, const, volatile, const volatile).decltype of the two calls. If both return the same type, the narrower call is considered implicit — the overload does not exist for that qualifier.const case an additional cross-category check is performed (see MSVC note below).if constexpr guards::std::is_same_v) are placed inside if constexpr blocks that first verify callability, ensuring decltype is never evaluated on an ill-formed call expression. This avoids the Clang limitation where requires { requires EXPR; } inside a constexpr-evaluated lambda body is rejected.volatile overloads follow the same return-type discrimination rules. If the class has both volatile& and const volatile& overloads, their return types must also differ.void foo() const) is callable on both lvalues and rvalues. The macro treats such methods as having dedicated overloads for both categories, provided the return-type discrimination passes.const& ref-qualified member functions to be called on rvalues. This means can_rv_c will be true even when no const&& overload exists. To compensate, the macro performs a cross-category return-type comparison: it checks whether the return type of calling through const&& differs from calling through const&. If they match and no mutable/const rvalue return-type difference exists, the const&& call is deemed implicit and the predicate returns false.| method | Unqualified method name (may contain template keyword for explicit template arguments). |
| Type | A cv-ref qualified type, e.g. const MyClass &. |
| ... | Parameter types for the method call (may be empty). |