std::span<T,Extent>:: size_bytes
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::span
| Member functions | ||||
| Element access | ||||
|
(C++26)
|
||||
| Iterators | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Observers | ||||
|
span::size_bytes
|
||||
| Subviews | ||||
| Non-member functions | ||||
| Non-member constant | ||||
| Deduction guides |
|
constexpr
size_type size_bytes
(
)
const
noexcept
;
|
(自 C++20 起) | |
返回序列的大小(以字节为单位)。
返回值
size ( ) * sizeof ( element_type ) 。
示例
运行此代码
#include <cstdint> #include <iostream> #include <span> constexpr static std::int32_t a[]{1, 2, 3, 4, 5}; constexpr static std::span s{a}; static_assert ( sizeof(int32_t) == 4 && std::size(a) == 5 && sizeof a == 20 && s.size() == 5 && s.size_bytes() == 20 ); int main() { // 通常,静态 span 仅包含一个指针: std::cout << sizeof(s) << '\n'; }
可能的输出:
8
参见
|
(C++20)
|
返回序列中的元素数量
(公开成员函数) |