(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 |
Member functions | ||||
Element access | ||||
(C++26) | ||||
Iterators | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
Observers | ||||
Subviews | ||||
Non-member functions | ||||
as_bytesas_writable_bytes | ||||
Non-member constant | ||||
Deduction guides |
Defined in header <span> | ||
template<class T,std::size_t N> std::span<conststd::byte, S/* see below */> | (1) | (since C++20) |
template<class T,std::size_t N> std::span<std::byte, S/* see below */> | (2) | (since C++20) |
Obtains a view to the object representation of the elements of the spans.
IfN
isstd::dynamic_extent, the extent of the returned spanS
is alsostd::dynamic_extent; otherwise it issizeof(T)* N.
as_writable_bytes
only participates in overload resolution ifstd::is_const_v<T> isfalse.
#include <cstddef>#include <iomanip>#include <iostream>#include <span> void print(floatconst x,std::span<conststd::byte>const bytes){std::cout<<std::setprecision(6)<<std::setw(8)<< x<<" = { "<<std::hex<<std::uppercase<<std::setfill('0');for(autoconst b: bytes)std::cout<<std::setw(2)<<std::to_integer<int>(b)<<' ';std::cout<<std::dec<<"}\n";} int main(){/* mutable */float data[1]{3.141592f}; autoconst const_bytes= std::as_bytes(std::span{data}); print(data[0], const_bytes); autoconst writable_bytes= std::as_writable_bytes(std::span{data}); // Change the sign bit that is the MSB (IEEE 754 Floating-Point Standard). writable_bytes[3]|=std::byte{0B1000'0000}; print(data[0], const_bytes);}
Possible output:
3.14159 = { D8 0F 49 40 }-3.14159 = { D8 0F 49 C0 }
implicitly creates objects in given storage with the object representation reused (function template)[edit] | |
(C++17) | the byte type (enum)[edit] |