网站建设找导师蓝林,哪些企业网站做得好,零基础可以学平面设计吗,家用电脑桌面做网站类型特性
类型特性定义一个编译时基于模板的结构#xff0c;以查询或修改类型的属性。
试图特化定义于 type_traits 头文件的模板导致未定义行为#xff0c;除了 std::common_type 可依照其所描述特化。
定义于type_traits头文件的模板可以用不完整类型实…类型特性
类型特性定义一个编译时基于模板的结构以查询或修改类型的属性。
试图特化定义于 type_traits 头文件的模板导致未定义行为除了 std::common_type 可依照其所描述特化。
定义于type_traits头文件的模板可以用不完整类型实例化除非另外有指定尽管通常禁止以不完整类型实例化标准库模板。 特性上的运算
变参的逻辑或元函数
std::disjunction templateclass... B struct disjunction; (1)(C17 起)
组成类型特性 B... 的逻辑析取等效地在特性序列上进行逻辑或。
特化 std::disjunctionB1, ..., BN 有一个公开且无歧义的基类即
若 sizeof...(B) 0 则为 std::false_type 否则若 B1, ..., BN 中有 bool(Bi::value) true 则为首个 Bi 或者若无这种类型则为 BN 。
不隐藏 disjunction 和 operator 以外的基类成员名而它们在 disjunction 中无歧义地可用。
析取是短路的若存在模板类型参数 Bi 满足 bool(Bi::value) ! false则实例化 disjunctionB1, ..., BN::value 不要求 j i 的 Bj::value 的实例化。
模板形参
B...-每个要实例化 Bi::value 的模板参数 Bi 必须可用作基类且定义了可转换到 bool 的成员 value
辅助变量模板 templateclass... B inline constexpr bool disjunction_v disjunctionB...::value; (C17 起)
可能的实现
templateclass... struct disjunction : std::false_type { };
templateclass B1 struct disjunctionB1 : B1 { };
templateclass B1, class... Bn
struct disjunctionB1, Bn... : std::conditional_tbool(B1::value), B1, disjunctionBn... { };
注意
disjunction 的特化不需要继承自 std::true_type 或 std::false_type 它简单地继承自首个 B 其 ::value 在显式转换为 bool 后为 true 或在它们都转换为 false 时继承自最后的 B 。例如 std::disjunctionstd::integral_constantint, 2, std::integral_constantint, 4::value 为 2 。
disjunction 的短路实例化异于折叠表达式如 (... || Bs::value) 的折叠表达式实例化 Bs 中的每个 B 而 std::disjunction_vBs... 一旦能确定值就停止实例化。这在之后的类型实例化代价高昂或以错误的类型实例化能导致硬错误时特别有用。
调用示例
#include type_traits
#include string
#include iostreamnamespace std
{
templateclass... struct disjunction : std::false_type { };templateclass B1 struct disjunctionB1 : B1 { };template bool B, class T, class F
using conditional_t typename conditionalB, T, F::type;templateclass B1, class... Bn
struct disjunctionB1, Bn...
: conditional_tbool(B1::value), B1, disjunctionBn... { };
}templateclass... Ts
struct first_constructible
{templateclass T, class...Argsstruct is_constructible_x : std::is_constructibleT, Args...{using type T;};struct fallback{static constexpr bool value true;using type void; // 若找不到内容则返回的类型};templateclass... Argsusing with typename std::disjunctionis_constructible_xTs, Args......,fallback::type;
};int main()
{// OK 不实例化 is_constructibleFoo, doublestd::cout std::is_samefirst_constructiblestd::string, int::with, std::string::value: std::is_samefirst_constructiblestd::string, int::with, std::string::value std::endl;std::cout std::is_samefirst_constructiblestd::string, int::withconst char*, std::string::value: std::is_samefirst_constructiblestd::string, int::withconst char*, std::string::value std::endl;std::cout std::is_samefirst_constructiblestd::string, int::withvoid*, void::value: std::is_samefirst_constructiblestd::string, int::withvoid*, void::value std::endl;return 0;
}输出
std::is_samefirst_constructiblestd::string, int::with, std::string::value: 1
std::is_samefirst_constructiblestd::string, int::withconst char*, std::string::value: 1
std::is_samefirst_constructiblestd::string, int::withvoid*, void::value: 1