std::is_bounded_array

来自cppreference.com
< cpp‎ | types
 
 
元编程库
类型特性
类型类别
(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)
is_bounded_array
(C++20)
类型特性常量
元函数
(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 is_bounded_array;
(C++20 起)

std::is_bounded_array一元类型特性 (UnaryTypeTrait)

检查 T 是否为拥有已知边界的数组类型。

如果 T 是有已知边界的数组,那么成员常量 value 等于 true。对于其它类型,value 等于 false

添加 std::is_bounded_arraystd::is_bounded_array_v 的特化的程序行为未定义。

模板形参

T - 要检查的类型

辅助变量模板

template< class T >
inline constexpr bool is_bounded_array_v = is_bounded_array<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>

可能的实现

template<class T>
struct is_bounded_array: std::false_type {};
 
template<class T, std::size_t N>
struct is_bounded_array<T[N]> : std::true_type {};

注解

功能特性测试 标准 备注
__cpp_lib_bounded_array_traits 201902L (C++20) std::is_bounded_array, std::is_unbounded_array

示例

#include <iostream>
#include <type_traits>
 
class A {};
 
int main() 
{
    std::cout << std::boolalpha;
    std::cout << std::is_bounded_array_v<A> << '\n';
    std::cout << std::is_bounded_array_v<A[]> << '\n';
    std::cout << std::is_bounded_array_v<A[3]> << '\n';
    std::cout << std::is_bounded_array_v<float> << '\n';
    std::cout << std::is_bounded_array_v<int> << '\n';
    std::cout << std::is_bounded_array_v<int[]> << '\n';
    std::cout << std::is_bounded_array_v<int[3]> << '\n';
}

输出:

false
false
true
false
false
false
true

参阅

(C++11)
检查类型是否是数组类型
(类模板)
检查类型是否为有未知边界的数组类型
(类模板)
(C++11)
获取数组类型在指定维度的大小
(类模板)