std::is_literal_type
类型特性 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
编译时有理数算术 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
编译时整数序列 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14)
|
在标头
<type_traits>
定义
|
||
template<
class T
>
struct is_literal_type; |
(C++11
起) (C++17 中弃用) (C++20 中移除) |
|
std::is_literal_type
是一元类型特性 (UnaryTypeTrait)
。
由于对泛型编程而言十分鸡肋,这项类型特性已经弃用[1]并移除[2] 。
如果 T
满足所有字面类型 (LiteralType)
的要求,那么成员常量 value
等于 true。对于其它类型,value
等于 false。
如果 std::remove_all_extents_t<T> 是(可有 cv 限定的)void 以外的不完整类型,那么行为未定义。
添加 std::is_literal_type
或 std::is_literal_type_v
的特化的程序行为未定义。
模板形参
T | - | 要检查的类型 |
辅助变量模板
template<
class T
>
inline constexpr bool is_literal_type_v = is_literal_type<T>::value; |
(C++17
起) (弃用) (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> |
注意
只有字面类型能作为 constexpr 函数的参数或返回类型。只有字面类能拥有 constexpr 成员函数。
示例
#include <type_traits> struct A { int m; }; static_assert(std::is_literal_type_v<A> == true); struct B { virtual ~B(); }; static_assert(std::is_literal_type_v<B> == false); int main() {}
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
---|---|---|---|
LWG 2015 | C++11 | T 可以是不完整类类型的未知边界数组
|
此时行为未定义 |
外部链接
- ↑ Alisdair Meredith. "Deprecate the is_literal Trait". Deprecating Vestigial Library Parts in C++17. "The is_literal type trait offers negligible value to generic code, as what is really needed is the ability to know that a specific construction would produce constant initialization."
- ↑ Alisdair Meredith, Stephan T. Lavavej, Tomasz Kamiński. "Deprecated type traits". Reviewing Deprecated Facilities of C++17 for C++20. "Strong recommendation: Remove the traits that can live on as zombies. [...] Toronto Review: Accept strong recommendation, strike from C++20."