CppDS.com

C++ 98 11 14 17 20 手册

std::has_strong_structural_equality

来自cppreference.com
< cpp‎ | types
 
 
工具库
通用工具
日期和时间
函数对象
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20)
swap 与类型运算
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
常用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等字符串转换
(C++17)
(C++17)
 
类型支持
基本类型
基础类型
定宽整数类型 (C++11)
数值极限
C 数值极限接口
运行时类型信息
类型特性
类型类别
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
类型属性
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20 前)
(C++11)(C++20 中弃用)
(C++11)
类型特性常量
元函数
(C++17)
常量求值语境
受支持操作
关系与属性查询
类型修改
(C++11)(C++11)(C++11)
类型变换
(C++11)
(C++11)
(C++17)
(C++11)(C++20 前)(C++17)
 
定义于头文件 <type_traits>
template< class T >
struct has_strong_structural_equality;
(C++20 起)

T 拥有强结构相等性,则提供等于 true 的成员常量 value 。对于任何其他类型 valuefalse

添加 has_strong_structural_equalityhas_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

参阅

关闭