Represents a read-only view of a contiguous block of bytes.
ConstBuf is intended for passing ownership of read-only data, or providing an unowned view, optionally slicing the view between layers. Unlike Buf, ConstBuf does not support Reclaim() or expose its base pointer. Once a ConstBuf is sliced or truncated, the excluded bytes cannot be recovered.
An empty() ConstBuf has no bytes (size() == 0). A null ConstBuf has no bytes, and its data() pointer is nullptr. A ConstBuf is null when default-constructed, moved-from, or reset.
An empty ConstBuf is not necessarily null (for example, if it has been sliced or truncated to length 0), in which case data() returns a non-null pointer.
Nullness can be checked via comparison to nullptr (buf == nullptr, buf != nullptr). operator bool is not provided to prevent confusion between nullness and emptiness.
Public Types | |
| using | value_type = std::byte |
| using | size_type = size_t |
| using | difference_type = ptrdiff_t |
| using | pointer = const std::byte * |
| using | reference = const std::byte & |
| using | iterator = containers::ConstPtrIterator< ConstBuf > |
| using | const_pointer = const std::byte * |
| using | const_reference = const std::byte & |
| using | const_iterator = containers::ConstPtrIterator< ConstBuf > |
Public Member Functions | |
| constexpr | ConstBuf ()=default |
Constructs a null ConstBuf. | |
| constexpr | ConstBuf (std::nullptr_t) noexcept |
Constructs a null ConstBuf. | |
| constexpr | ConstBuf (ConstBuf &&other) noexcept |
| constexpr | ConstBuf (Buf &&other) noexcept |
| ConstBuf (const ConstBuf &)=delete | |
| ~ConstBuf () | |
| Destructor. Releases the owned memory (if any) back to the allocator. | |
| ConstBuf & | operator= (ConstBuf &&other) noexcept |
| ConstBuf & | operator= (Buf &&other) noexcept |
| ConstBuf & | operator= (const ConstBuf &)=delete |
| ConstBuf & | operator= (std::nullptr_t) noexcept |
| operator bool () const =delete | |
| reference | operator[] (size_t index) const |
| Accesses the byte at the specified index. | |
| constexpr pointer | data () const |
| constexpr size_t | size () const |
| Returns the number of bytes in the buffer view. | |
| constexpr bool | empty () const |
| iterator | begin () const |
| Returns a read-only iterator pointing to the beginning of the data. | |
| iterator | end () const |
| Returns a read-only iterator pointing past the end of the data. | |
| const_iterator | cbegin () const |
| Returns a read-only iterator pointing to the beginning of the data. | |
| const_iterator | cend () const |
| Returns a read-only iterator pointing past the end of the data. | |
| constexpr Deallocator * | deallocator () const |
| void | reset () |
| Frees the owned memory (if any) and sets the buffer to null. | |
Static Public Member Functions | |
| static ConstBuf | Unowned (ConstByteSpan span) |
Creates an unowned ConstBuf from a ConstByteSpan. | |
| static ConstBuf | Unowned (const std::byte *data, size_t size_bytes) |
Creates an unowned ConstBuf from a pointer and size in bytes. | |
Friends | |
| class | Buf |
| class | multibuf::v2::internal::GenericMultiBuf |
| constexpr bool | operator== (const ConstBuf &lhs, std::nullptr_t) noexcept |
| constexpr bool | operator== (std::nullptr_t, const ConstBuf &rhs) noexcept |
| constexpr bool | operator!= (const ConstBuf &lhs, std::nullptr_t) noexcept |
| constexpr bool | operator!= (std::nullptr_t, const ConstBuf &rhs) noexcept |
| ConstBuf | Slice (ConstBuf &&const_buf, size_t offset, size_t length) |
| Buf | Slice (Buf &&buf, size_t offset, size_t length) |
Slices a mutable Buf by shifting its start address and setting its size. | |
| Buf | Reclaim (Buf &&buf, size_t prefix_count, size_t suffix_count) |
|
inlineconstexprnoexcept |
Move constructor.
The moved-from ConstBuf is left null.
|
inlineconstexpr |
|
inlineconstexpr |
Returns a pointer to the deallocator if this buffer owns the underlying memory allocation, or nullptr if the buffer is unowned or null.
|
inlineconstexpr |
Returns true if the buffer view is empty (has no bytes).
empty() returns true for both null buffers and non-null buffers of size zero (e.g. sliced or truncated to length 0).
|
explicitdelete |
operator bool is not provided to prevent confusion between nullness and emptiness. Use buf == nullptr to check for null, or buf.empty() for size 0.
Move assignment operator.
The moved-from ConstBuf is left null.
|
inlinenoexcept |
Frees the owned memory (if any) and sets the buffer to null. Same as reset().
Reclaims up to prefix_count bytes at the beginning and suffix_count bytes at the end of the buffer.
Slices a read-only ConstBuf by shifting its start address and setting its size.