|
Stratax 0.3.1
|
Fixed-size owner of aligned, contiguous element storage. More...
#include <Buffer.hpp>
Public Types | |
| using | value_type = T |
| Type of each stored element. | |
| using | size_type = std::size_t |
| Unsigned type used for element counts and indices. | |
| using | difference_type = std::ptrdiff_t |
| Signed type used for distances between iterators. | |
| using | reference = T & |
| Mutable element reference type. | |
| using | const_reference = const T & |
| Read-only element reference type. | |
| using | pointer = T * |
| Mutable pointer to an element. | |
| using | const_pointer = const T * |
| Read-only pointer to an element. | |
| using | iterator = pointer |
| Mutable contiguous random-access iterator type. | |
| using | const_iterator = const_pointer |
| Read-only contiguous random-access iterator type. | |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| Mutable iterator that traverses elements in reverse order. | |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
| Read-only iterator that traverses elements in reverse order. | |
Public Member Functions | |
| Buffer () noexcept | |
| Constructs an empty buffer that owns no allocation. | |
| Buffer (size_type size) | |
| Constructs a buffer with value-initialized elements. | |
| Buffer (size_type size, const_reference value) | |
Constructs a buffer with all elements initialized to value. | |
| Buffer (std::initializer_list< value_type > list) | |
| Constructs a buffer from an initializer list. | |
| Buffer (const Buffer &other) | |
| Copy-constructs a buffer with independent storage. | |
| Buffer (Buffer &&other) noexcept | |
| Move-constructs a buffer by transferring ownership. | |
| Buffer & | operator= (const Buffer &other) |
| Copy-assigns from another buffer. | |
| Buffer & | operator= (Buffer &&other) noexcept |
| Move-assigns from another buffer. | |
| ~Buffer () | |
| Destroys the buffer and releases owned storage. | |
| reference | operator[] (size_type index) noexcept |
| Returns an unchecked reference to an element. | |
| const_reference | operator[] (size_type index) const noexcept |
| Returns an unchecked const reference to an element. | |
| reference | front () |
| Returns a reference to the first element. | |
| const_reference | front () const |
| Returns a const reference to the first element. | |
| reference | back () |
| Returns a reference to the last element. | |
| const_reference | back () const |
| Returns a const reference to the last element. | |
| pointer | data () noexcept |
| Returns a pointer to the underlying contiguous storage. | |
| const_pointer | data () const noexcept |
| Returns a const pointer to the underlying contiguous storage. | |
| iterator | begin () noexcept |
| Returns a mutable iterator to the first element. | |
| const_iterator | begin () const noexcept |
| Returns a const iterator to the first element. | |
| const_iterator | cbegin () const noexcept |
| Returns a const iterator to the first element. | |
| iterator | end () noexcept |
| Returns a mutable iterator one past the final element. | |
| const_iterator | end () const noexcept |
| Returns a const iterator one past the final element. | |
| const_iterator | cend () const noexcept |
| Returns a const iterator one past the final element. | |
| reverse_iterator | rbegin () noexcept |
| Returns a mutable reverse iterator to the final element. | |
| const_reverse_iterator | rbegin () const noexcept |
| Returns a const reverse iterator to the final element. | |
| const_reverse_iterator | crbegin () const noexcept |
| Returns a const reverse iterator to the final element. | |
| reverse_iterator | rend () noexcept |
| Returns the past-the-end iterator for mutable reverse traversal. | |
| const_reverse_iterator | rend () const noexcept |
| Returns the past-the-end iterator for const reverse traversal. | |
| const_reverse_iterator | crend () const noexcept |
| Returns the past-the-end iterator for const reverse traversal. | |
| size_type | size () const noexcept |
| Returns the number of stored elements. | |
| bool | empty () const noexcept |
| Returns whether the buffer has no elements. | |
| void | fill (const_reference value) |
| Assigns a value to every element in the buffer. | |
| void | swap (Buffer &other) noexcept |
| Swaps storage and size with another buffer. | |
Static Public Member Functions | |
| static constexpr size_type | alignment () noexcept |
| Returns the alignment, in bytes, used for buffer allocations. | |
| static constexpr size_type | max_size () noexcept |
| Returns the largest element count that cannot overflow in bytes. | |
Fixed-size owner of aligned, contiguous element storage.
Buffer allocates storage with the requested alignment and manages the lifetime of every element in that storage. Its size cannot change after construction, although its elements remain mutable. Elements occupy one contiguous allocation, so pointers and random-access iterators can be used with standard-library algorithms.
Copy operations create an independent allocation and copy the elements. Move operations transfer the allocation in constant time and leave the source empty. Destruction releases every element followed by the aligned allocation, giving the class exclusive RAII ownership of its storage.
| T | Element type stored in the buffer. |
| Alignment | Allocation alignment in bytes. It must be a power of two and at least alignof(T). |
Definition at line 50 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::const_iterator = const_pointer |
Read-only contiguous random-access iterator type.
Definition at line 74 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::const_pointer = const T* |
Read-only pointer to an element.
Definition at line 70 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::const_reference = const T& |
Read-only element reference type.
Definition at line 66 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Read-only iterator that traverses elements in reverse order.
Definition at line 78 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::difference_type = std::ptrdiff_t |
Signed type used for distances between iterators.
Definition at line 62 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::iterator = pointer |
Mutable contiguous random-access iterator type.
Definition at line 72 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::pointer = T* |
Mutable pointer to an element.
Definition at line 68 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::reference = T& |
Mutable element reference type.
Definition at line 64 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::reverse_iterator = std::reverse_iterator<iterator> |
Mutable iterator that traverses elements in reverse order.
Definition at line 76 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::size_type = std::size_t |
Unsigned type used for element counts and indices.
Definition at line 60 of file Buffer.hpp.
| using stratax::core::Buffer< T, Alignment >::value_type = T |
Type of each stored element.
Definition at line 58 of file Buffer.hpp.
|
inlinenoexcept |
Constructs an empty buffer that owns no allocation.
size() is zero, empty() is true, and data() is nullptr.
Definition at line 114 of file Buffer.hpp.
|
inlineexplicit |
Constructs a buffer with value-initialized elements.
Each element is initialized from value_type{}. If element construction fails, already-constructed elements and the allocation are cleaned up.
| size | Number of elements to construct. |
| std::bad_array_new_length | If size exceeds max_size(). |
| std::bad_alloc | If storage allocation fails. |
| Any | exception thrown while constructing an element. |
Definition at line 129 of file Buffer.hpp.
|
inline |
Constructs a buffer with all elements initialized to value.
If an element copy fails, already-constructed elements and the allocation are cleaned up.
| size | Number of elements to construct. |
| value | Value copied into each element. |
| std::bad_array_new_length | If size exceeds max_size(). |
| std::bad_alloc | If storage allocation fails. |
| Any | exception thrown by value_type's copy constructor. |
Definition at line 148 of file Buffer.hpp.
|
inline |
Constructs a buffer from an initializer list.
Elements are copy-constructed in list order. If an element copy fails, already-constructed elements and the allocation are cleaned up.
| list | Source elements. |
| std::bad_array_new_length | If list size exceeds max_size(). |
| std::bad_alloc | If storage allocation fails. |
| Any | exception thrown by value_type's copy constructor. |
Definition at line 167 of file Buffer.hpp.
|
inline |
Copy-constructs a buffer with independent storage.
If copying an element fails, all elements already constructed in the new allocation are destroyed and the exception is propagated.
| other | Buffer to copy from. |
| std::bad_array_new_length | If other.size() exceeds max_size(). |
| std::bad_alloc | If storage allocation fails. |
| Any | exception thrown by value_type's copy constructor. |
Definition at line 196 of file Buffer.hpp.
|
inlinenoexcept |
Move-constructs a buffer by transferring ownership.
After construction, other is empty and owns no allocation. Existing pointers and iterators into other remain valid and now refer to elements owned by the newly constructed buffer. Element move constructors are not invoked.
| other | Buffer to move from. |
Definition at line 224 of file Buffer.hpp.
|
inline |
Destroys the buffer and releases owned storage.
Each live element is destroyed before the allocation is released.
Definition at line 298 of file Buffer.hpp.
|
inlinestaticconstexprnoexcept |
Returns the alignment, in bytes, used for buffer allocations.
This is a compile-time property of the Buffer specialization.
Definition at line 88 of file Buffer.hpp.
|
inline |
Returns a reference to the last element.
| Exceptions::IndexError | If the buffer is empty. |
Definition at line 358 of file Buffer.hpp.
|
inline |
Returns a const reference to the last element.
| Exceptions::IndexError | If the buffer is empty. |
Definition at line 370 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const iterator to the first element.
Definition at line 415 of file Buffer.hpp.
|
inlinenoexcept |
Returns a mutable iterator to the first element.
Definition at line 409 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const iterator to the first element.
Definition at line 421 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const iterator one past the final element.
Definition at line 439 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const reverse iterator to the final element.
Definition at line 457 of file Buffer.hpp.
|
inlinenoexcept |
Returns the past-the-end iterator for const reverse traversal.
Definition at line 475 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const pointer to the underlying contiguous storage.
Elements occupy the range [data(), data() + size()) when non-empty. The pointer remains valid until this buffer is assigned to, moved from, swapped, or destroyed.
Definition at line 399 of file Buffer.hpp.
|
inlinenoexcept |
Returns a pointer to the underlying contiguous storage.
Elements occupy the range [data(), data() + size()) when non-empty. The pointer remains valid until this buffer is assigned to, moved from, swapped, or destroyed.
Definition at line 386 of file Buffer.hpp.
|
inlinenoexcept |
Returns whether the buffer has no elements.
true if size() is zero; otherwise false. Definition at line 494 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const iterator one past the final element.
Definition at line 433 of file Buffer.hpp.
|
inlinenoexcept |
Returns a mutable iterator one past the final element.
Definition at line 427 of file Buffer.hpp.
|
inline |
Assigns a value to every element in the buffer.
Assignment proceeds from the first element to the last. If an assignment throws, earlier elements retain their new values while the remaining elements keep their previous values.
| value | Value copied into each element. |
| Any | exception thrown by value_type's copy-assignment operator. |
Definition at line 507 of file Buffer.hpp.
|
inline |
Returns a reference to the first element.
| Exceptions::IndexError | If the buffer is empty. |
Definition at line 334 of file Buffer.hpp.
|
inline |
Returns a const reference to the first element.
| Exceptions::IndexError | If the buffer is empty. |
Definition at line 346 of file Buffer.hpp.
|
inlinestaticconstexprnoexcept |
Returns the largest element count that cannot overflow in bytes.
This is an arithmetic limit rather than a promise that an allocation of that size will succeed.
std::numeric_limits<size_type>::max() / sizeof(value_type). Definition at line 102 of file Buffer.hpp.
|
inlinenoexcept |
Move-assigns from another buffer.
Existing elements are destroyed before ownership is transferred. After assignment, other is empty and owns no allocation. Pointers and iterators into other remain valid and now refer to elements owned by this buffer; those into this buffer's former storage are invalidated.
| other | Buffer to move from. |
Definition at line 270 of file Buffer.hpp.
|
inline |
Copy-assigns from another buffer.
This operation provides the strong exception guarantee: if allocation or element copying fails, this buffer is unchanged. On success, previous pointers, references, and iterators into this buffer are invalidated.
| other | Buffer to copy from. |
| std::bad_array_new_length | If other.size() exceeds max_size(). |
| std::bad_alloc | If storage allocation fails. |
| Any | exception thrown by value_type's copy constructor. |
Definition at line 245 of file Buffer.hpp.
|
inlinenoexcept |
Returns an unchecked const reference to an element.
| index | Element position. |
index. index < size(); otherwise behavior is undefined. Definition at line 325 of file Buffer.hpp.
|
inlinenoexcept |
Returns an unchecked reference to an element.
| index | Element position. |
index. index < size(); otherwise behavior is undefined. Definition at line 315 of file Buffer.hpp.
|
inlinenoexcept |
Returns a const reverse iterator to the final element.
Definition at line 451 of file Buffer.hpp.
|
inlinenoexcept |
Returns a mutable reverse iterator to the final element.
Definition at line 445 of file Buffer.hpp.
|
inlinenoexcept |
Returns the past-the-end iterator for const reverse traversal.
Definition at line 469 of file Buffer.hpp.
|
inlinenoexcept |
Returns the past-the-end iterator for mutable reverse traversal.
Definition at line 463 of file Buffer.hpp.
|
inlinenoexcept |
Returns the number of stored elements.
The count is fixed between construction and assignment.
Definition at line 486 of file Buffer.hpp.
|
inlinenoexcept |
Swaps storage and size with another buffer.
| other | Buffer to swap with. |
This operation does not move, copy, or swap individual elements. Iterators and pointers continue to refer to the same elements, now owned by the other buffer. References are likewise unaffected.
Definition at line 523 of file Buffer.hpp.