名稱空間
變體
操作

std::span<T,Extent>::size_bytes

來自 cppreference.com
< cpp‎ | 容器‎ | span
constexpr size_type size_bytes() const noexcept;
(C++20 起)

返回序列的位元組大小。

目錄

[編輯] 引數

(無)

[編輯] 返回值

序列的位元組大小,即 size() * sizeof(element_type)

[編輯] 示例

#include <cstdint>
#include <span>
 
int main()
{
    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
    );
}

[編輯] 參閱

(C++20)
返回序列中的元素數量
(公共成員函式) [編輯]