跳到主要内容

std::span size_bytes() 方法

constexpr size_type size_bytes() const noexcept;

返回序列的字节大小,即 size() * sizeof(element_type)。

参数

(无)

返回值

序列的字节大小。

复杂度

常数 - O(1)

示例

Main.cpp
#include <span>
#include <cstdint>

int main()
{
static constexpr std::int32_t a[] { 1, 2, 3, 4, 5 };
constexpr std::span s{a};

static_assert( sizeof(int32_t) == 4 );
static_assert( std::size(a) == 5 );
static_assert( sizeof(a) == 20 );
static_assert( s.size() == 5 );
static_assert( s.size_bytes() == 20 );
}
输出
No output expected
本文源自此 CppReference 页面。它可能为了改进或编辑者的偏好而进行了修改。点击“编辑此页面”以查看此文档的所有更改。
悬停查看原始许可证。

std::span size_bytes() 方法

constexpr size_type size_bytes() const noexcept;

返回序列的字节大小,即 size() * sizeof(element_type)。

参数

(无)

返回值

序列的字节大小。

复杂度

常数 - O(1)

示例

Main.cpp
#include <span>
#include <cstdint>

int main()
{
static constexpr std::int32_t a[] { 1, 2, 3, 4, 5 };
constexpr std::span s{a};

static_assert( sizeof(int32_t) == 4 );
static_assert( std::size(a) == 5 );
static_assert( sizeof(a) == 20 );
static_assert( s.size() == 5 );
static_assert( s.size_bytes() == 20 );
}
输出
No output expected
本文源自此 CppReference 页面。它可能为了改进或编辑者的偏好而进行了修改。点击“编辑此页面”以查看此文档的所有更改。
悬停查看原始许可证。