std::span<T,Extent>::size
来自cppreference.com
constexpr size_type size() const noexcept; |
(C++20 起) | |
返回 span
中的元素数。
目录 |
[编辑] 返回值
span
中的元素数。
[编辑] 注解
功能特性测试宏 | 值 | 标准 | 功能特性 |
---|---|---|---|
__cpp_lib_ssize |
201902L |
(C++20) | std::ssize 和无符号的 std::span::size
|
[编辑] 示例
运行此代码
#include <span> int main() { constexpr static int c_array[]{1, 2, 3, 4, 5, 6, 7, 8}; constexpr std::span<const int> span{c_array}; static_assert(8 == span.size()); static_assert(7 == span.first(7).size()); static_assert(6 == span.first<6>().size()); static_assert(5 == span.last(5).size()); static_assert(4 == span.last<4>().size()); static_assert(3 == span.subspan(2, 3).size()); static_assert(2 == span.subspan<3, 2>().size()); static_assert(1 == span.subspan<7>().size()); }
[编辑] 参阅
构造 span (公开成员函数) | |
返回以字节计的序列大小 (公开成员函数) |