std::has_strong_structural_equality
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    | 在标头  <type_traits>定义 | ||
| template< class T > struct has_strong_structural_equality; | (C++20 起) | |
若 T 拥有强结构相等性,则提供等于 true 的成员常量 value 。对于任何其他类型 value 为 false 。
添加 has_strong_structural_equality 或 has_strong_structural_equality_v 的特化的程序行为未定义。
模板形参
| T | - | 要检查的类型 | 
辅助变量模板
| template< class T > inline constexpr bool has_strong_structural_equality_v = has_strong_structural_equality<T>::value; | (C++20 起) | |
继承自 std::integral_constant
成员常量
| value [静态] | 若 T拥有强结构相等性则为 true ,否则为 false(公开静态成员常量) | 
成员函数
| operator bool | 转换对象为 bool ,返回 value(公开成员函数) | 
| operator() (C++14) | 返回 value(公开成员函数) | 
成员类型
| 类型 | 定义 | 
| value_type | bool | 
| type | std::integral_constant<bool, value> | 
注解
此类型特征可用于检查一个类型能否用作非类型模板形参。
示例
运行此代码
#include <type_traits> #include <cstring> #include <algorithm> #include <iostream> template<std::size_t N> struct fixed_string { constexpr fixed_string(const char (&s)[N + 1]) { std::copy_n(s, N + 1, m_data); } bool operator==(const fixed_string&) const = default; char m_data[N + 1]; }; template<std::size_t N> struct broken_fixed_string { constexpr broken_fixed_string(const char (&s)[N + 1]) { std::copy_n(s, N + 1, m_data); } bool operator==(const broken_fixed_string &rhs) const { return std::memcmp(m_data, rhs.m_data, N + 1) == 0; } char m_data[N + 1]; }; int main() { std::cout << std::boolalpha << std::has_strong_structural_equality_v<fixed_string<42>> << '\n' << std::has_strong_structural_equality_v<broken_fixed_string<42>> << '\n'; }
输出:
true false