Namespaces
Variants
Views
Actions

std::as_bytes, std::as_writable_bytes

From cppreference.com
< cpp‎ | container‎ | span
Revision as of 23:15, 18 March 2018 by T. Canens (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 
 
template< class T, std::ptrdiff_t N>
std::span<const std::byte, S/* see below */> as_bytes(std::span<T, N> s) noexcept;
(1)
template< class T, std::ptrdiff_t N>
std::span<std::byte, S/* see below */> as_writable_bytes(std::span<T, N> s) noexcept;
(2)

Obtains a view to the object representation of the elements of the span s.

If N is std::dynamic_extent, the extent of the returned span S is also std::dynamic_extent; otherwise it is std::ptrdiff_t(sizeof(T)) * N.

as_writable_bytes only participates in overload resolution if std::is_const_v<T> is false.

Return value

1) A span constructed with {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()}.
2) A span constructed with {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()}.