定义于头文件
<type_traits>
|
||
template< class T >
struct is_literal_type; |
(C++11 起) (C++17 中弃用) |
|
若 T
满足所有字面类型 (LiteralType
) 的要求,则提供等于 true 的成员常量 value
。对于任何其他类型, value
为 false 。
若 std::remove_all_extents_t<T> 为不完整类型且非(可有 cv 限定的) void 则行为未定义。
目录 |
T | - | 要检查的类型 |
template< class T >
inline constexpr bool is_literal_type_v = is_literal_type<T>::value; |
(C++17 起) (弃用) |
|
value
[静态]
|
若 T 为字面类型则为 true ,否则为 false (公开静态成员常量) |
operator bool
|
转换对象为 bool ,返回 value (公开成员函数) |
operator()
(C++14)
|
返回 value (公开成员函数) |
类型 | 定义 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
唯有字面类型能作为 constexpr 函数的参数或自之返回。只有字面类能拥有 constexpr 成员函数。
#include <iostream> #include <type_traits> struct A { int m; }; struct B { virtual ~B(); }; int main() { std::cout << std::boolalpha; std::cout << std::is_literal_type<A>::value << '\n'; std::cout << std::is_literal_type<B>::value << '\n'; }
输出:
true false