Namespaces
Variants

std:: is_literal_type

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
is_literal_type
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定义于头文件 <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 >
constexpr bool is_literal_type_v = is_literal_type < T > :: value ;
(C++17 起)
(已弃用)
(C++20 中移除)

继承自 std:: integral_constant

成员常量

value
[static]
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 可能是未知边界的
不完整类类型的数组
此情况下行为
未定义

外部链接

  1. Alisdair Meredith. "弃用 is_literal 类型特征" . C++17 中废弃遗留库组件 . " is_literal 类型特征对泛型代码提供的价值微乎其微,真正需要的是能够判断特定构造是否会产生常量初始化的能力。"
  2. Alisdair Meredith, Stephan T. Lavavej, Tomasz Kamiński. "废弃的类型特征" . 重新评估 C++17 废弃特性以用于 C++20 . " 强烈建议: 移除那些可以僵尸形式继续存在的特征。[...] 多伦多评审意见: 接受强烈建议,从 C++20 中删除。"