std::as_bytes, std::as_writable_bytes_C++中文网

template< class T, std::size_t N>
std::span<const std::byte, S/* see below */> as_bytes(std::span<T, N> s) noexcept;

(1)

template< class T, std::size_t N>
std::span<std::byte, S/* see below */> as_writable_bytes(std::span<T, N> s) noexcept;

(2)

获得对 span s 的元素的对象表示的视图。

Nstd::dynamic_extent ,则返回的 span S 的长度亦为 std::dynamic_extent ;否则它是 sizeof(T) * N

as_writable_bytes 仅若 std::is_const_v<T>false 才参与重载决议。

返回值

1){reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()} 构造的 span 。

2){reinterpret_cast<std::byte*>(s.data()), s.size_bytes()} 构造的 span 。