默认相等运算符是否有任何 C++20 功能测试?
Is any C++20 feature test for defaulted equal operator?
我想使用默认的等于运算符 bool operator ==(...) = default;
如果只有编译器支持它,否则我仍然可以使用现有的实现。
但是我在https://en.cppreference.com/w/cpp/feature_test
中找不到合适的功能测试
指出正确的功能测试或帮助修复此代码:
struct Some {
constexpr bool operator == (const Some& rhs) const noexcept
#if __cpp_what?
= default;
#else
{
...
}
#endif
};
因为默认比较与
紧密相关
- P1186R3:你什么时候真正使用
<=>
?
您也可以对默认比较的子集情况使用 __cpp_impl_three_way_comparison
功能测试。另见 P1185R2(<=> != ==
)。
您要找的文件是SD-FeatureTest。它与所有提案和所有宏观价值的所有历史联系在一起。
默认比较在这个意义上有点独特,因为虽然它是一种语言特性,但它也有一个强大的库组件:为了使用 <=>
,你需要 #include <compare>
并使用 header 中定义的比较类型。因此,这里有两个宏:
__cpp_impl_three_way_comparison
__cpp_lib_three_way_comparison
语言宏实际上是为标准库设计的,仅当编译器支持时才提供库功能。
库宏是供用户(即您)使用的宏。
我想使用默认的等于运算符 bool operator ==(...) = default;
如果只有编译器支持它,否则我仍然可以使用现有的实现。
但是我在https://en.cppreference.com/w/cpp/feature_test
中找不到合适的功能测试指出正确的功能测试或帮助修复此代码:
struct Some {
constexpr bool operator == (const Some& rhs) const noexcept
#if __cpp_what?
= default;
#else
{
...
}
#endif
};
因为默认比较与
紧密相关- P1186R3:你什么时候真正使用
<=>
?
您也可以对默认比较的子集情况使用 __cpp_impl_three_way_comparison
功能测试。另见 P1185R2(<=> != ==
)。
您要找的文件是SD-FeatureTest。它与所有提案和所有宏观价值的所有历史联系在一起。
默认比较在这个意义上有点独特,因为虽然它是一种语言特性,但它也有一个强大的库组件:为了使用 <=>
,你需要 #include <compare>
并使用 header 中定义的比较类型。因此,这里有两个宏:
__cpp_impl_three_way_comparison
__cpp_lib_three_way_comparison
语言宏实际上是为标准库设计的,仅当编译器支持时才提供库功能。
库宏是供用户(即您)使用的宏。