XTE _ DEFINE_CAST ()
Defined in header <xte/preproc/define_cast.hpp> Deduplicates the repetition required for defining the type,
noexcept specifier, requires clause, and body of a conversion function template.Definition
#define XTE_DEFINE_CAST (ATTR_SPEC ,THIS ,... )\ ATTR_SPEC operator decltype (/* ... */ )(this THIS )\ noexcept (noexcept (__VA_ARGS__ ))\ requires (requires {__VA_ARGS__ ; })\ {return (__VA_ARGS__ ); }
ATTR_SPEC and THIS may optionally be wrapped in parentheses.Example
[View in Compiler Explorer]struct Wrapper {int value ;XTE_DEFINE_CAST (constexpr ,auto&& self ,XTE_FWD (self ).value ) };void take_rvalue (int&& ) {}static_assert (requires {take_rvalue (Wrapper (5 )); });void take_lvalue (int& ) {}static_assert (requires {take_lvalue (xte ::as_lvalue (Wrapper (5 ))); });