std::span size_bytes() method
- od C++20
constexpr size_type size_bytes() const noexcept;
Returns the size of the sequence in bytes, i.e., size() * sizeof(element_type).
Parameters
(none)
Return value
The size of the sequence in bytes.
Complexity
Constant - O(1).
Example
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 );
}
Output
No output expected
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.
Hover to see the original license.