HikoGUI
A low latency retained GUI
|
#include <hikogui/container/lean_vector.hpp>
Public Types | |
using | value_type = T |
using | pointer = value_type * |
using | const_pointer = value_type const * |
using | reference = value_type& |
using | const_reference = value_type const& |
using | iterator = value_type * |
using | const_iterator = value_type const * |
using | reverse_iterator = std::reverse_iterator<iterator> |
using | const_reverse_iterator = std::reverse_iterator<const_iterator> |
using | size_type = std::size_t |
using | difference_type = std::ptrdiff_t |
using | allocator_type = std::allocator<value_type> |
Public Member Functions | |
constexpr allocator_type | get_allocator () const noexcept |
The allocator_type used to allocate items. | |
constexpr | lean_vector () noexcept=default |
Construct an empty vector. | |
~lean_vector () | |
Destruct the vector. | |
lean_vector (lean_vector const &other) | |
Copy-construct a vector. | |
lean_vector (lean_vector &&other) noexcept(std::is_nothrow_move_constructible_v< value_type >) | |
Move-construct a vector. | |
lean_vector & | operator= (lean_vector const &other) noexcept |
Copy-assign a vector. | |
lean_vector & | operator= (lean_vector &&other) noexcept |
Move-assign a vector. | |
void | swap (lean_vector &other) noexcept |
lean_vector (size_type count) | |
lean_vector (size_type count, value_type const &value) | |
lean_vector (std::input_iterator auto first, std::input_iterator auto last) | |
Construct a vector with the data pointed by iterators. | |
lean_vector (std::initializer_list< value_type > list) | |
Construct a vector with the given initializer list. | |
void | assign (size_type count, value_type const &value) |
Replace the data in the vector. | |
void | assign (std::input_iterator auto first, std::input_iterator auto last) |
Replace the data in the vector. | |
void | assign (std::initializer_list< value_type > list) |
Replace the data in the vector. | |
pointer | data () noexcept |
Get a pointer to the first item. | |
const_pointer | data () const noexcept |
Get a const-pointer to the first item. | |
constexpr bool | empty () const noexcept |
Check if the vector is empty. | |
constexpr size_type | size () const noexcept |
Get the number of items in the vector. | |
constexpr size_type | max_size () const noexcept |
constexpr size_t | short_capacity () const noexcept |
The maximum number of items that can fit without allocation. | |
size_t | capacity () const noexcept |
Get the current capacity of the vector. | |
reference | at (size_type index) |
Get a reference to an item in the vector. | |
const_reference | at (size_type index) const |
Get a const-reference to an item in the vector. | |
reference | operator[] (size_type index) noexcept |
Get a reference to an item in the vector. | |
const_reference | operator[] (size_type index) const noexcept |
Get a const-reference to an item in the vector. | |
reference | front () noexcept |
Get a reference to the first item in the vector. | |
const_reference | front () const noexcept |
Get a const-reference to the first item in the vector. | |
reference | back () noexcept |
Get a reference to the last item in the vector. | |
const_reference | back () const noexcept |
Get a const-reference to the last item in the vector. | |
iterator | begin () noexcept |
Get an iterator to the first item in the vector. | |
const_iterator | begin () const noexcept |
Get an const-iterator to the first item in the vector. | |
const_iterator | cbegin () const noexcept |
Get an const-iterator to the first item in the vector. | |
iterator | end () noexcept |
Get an iterator beyond the last item in the vector. | |
const_iterator | end () const noexcept |
Get an const-iterator beyond the last item in the vector. | |
const_iterator | cend () const noexcept |
Get an const-iterator beyond the last item in the vector. | |
void | clear () noexcept |
Remove all items from the vector. | |
void | reserve (size_type new_capacity) |
Reserve capacity for items. | |
void | shrink_to_fit () |
Shrink the allocation to fit the current number of items. | |
template<typename... Args> | |
iterator | emplace (const_iterator pos, Args &&...args) |
Construct in-place a new item. | |
iterator | insert (const_iterator pos, value_type const &value) |
Insert a new item. | |
iterator | insert (const_iterator pos, value_type &&value) |
Insert a new item. | |
iterator | insert (const_iterator pos, size_type count, value_type const &value) |
Insert a new item. | |
template<std::input_iterator First, std::input_iterator Last> | |
iterator | insert (const_iterator pos, First first, Last last) |
Insert new items. | |
iterator | insert (const_iterator pos, std::initializer_list< value_type > list) |
Insert new items. | |
iterator | erase (const_iterator pos) |
Erase an item at position. | |
iterator | erase (const_iterator first, const_iterator last) |
Erase an items. | |
template<typename... Args> | |
reference | emplace_back (Args &&...args) |
In-place construct an item at the end of the vector. | |
void | push_back (value_type const &value) |
Copy an item to the end of the vector. | |
void | push_back (value_type &&value) |
Move an item to the end of the vector. | |
void | pop_back () |
Remove the last item from the vector. | |
void | resize (size_type new_size) |
Resize a vector. | |
void | resize (size_type new_size, value_type const &value) |
Resize a vector. | |
Static Public Attributes | |
static constexpr size_t | value_alignment = alignof(value_type) |
Friends | |
bool | operator== (lean_vector const &lhs, lean_vector const &rhs) noexcept |
Compare two vectors. | |
auto | operator<=> (lean_vector const &lhs, lean_vector const &rhs) noexcept |
Compare two vectors lexicographically. | |
size_type | erase (lean_vector &c, value_type const &value) |
Erase items of a value from a vector. | |
template<typename Pred > | |
size_type | erase (lean_vector &c, Pred pred) |
Erase items of a value from a vector. | |
void | swap (lean_vector &lhs, lean_vector &rhs) noexcept |
Lean-vector with (SVO) short-vector-optimization.
The maximum number of items in SVO are:(sizeof(T *) * 3 - 1) / sizeof(T)
|
constexprdefaultnoexcept |
Construct an empty vector.
|
inline |
Destruct the vector.
|
inline |
Copy-construct a vector.
This will copy a vector. If the copy requires an allocation the new allocation will fit the number of items exactly.
other | The vector to copy. |
|
inlinenoexcept |
Move-construct a vector.
This will steal the allocation from the other vector, or move the items if the number of items is less than or equal to short_capacity()
.
other | The vector to move. |
|
inline |
Construct a vector with the data pointed by iterators.
first | An iterator pointing to the first item to copy. |
last | An iterator pointing beyond the last item to copy. |
|
inline |
Construct a vector with the given initializer list.
list | The list of values to copy into the vector. |
|
inline |
Replace the data in the vector.
count | The number of times to copy value into the vector. |
value | The value to copy into the vector. |
|
inline |
Replace the data in the vector.
list | A list of data to copy into the vector. |
|
inline |
Replace the data in the vector.
first | A iterator pointing to the first value to copy. |
last | A iterator pointing beyond the last value to copy. |
|
inline |
Get a reference to an item in the vector.
index | The index to the item in the vector. |
std::out_of_range | When index points beyond the size of the vector. |
|
inline |
Get a const-reference to an item in the vector.
index | The index to the item in the vector. |
std::out_of_range | When index points beyond the size of the vector. |
|
inlinenoexcept |
Get a const-reference to the last item in the vector.
|
inlinenoexcept |
Get a reference to the last item in the vector.
|
inlinenoexcept |
Get an const-iterator to the first item in the vector.
|
inlinenoexcept |
Get an iterator to the first item in the vector.
|
inlinenoexcept |
Get the current capacity of the vector.
|
inlinenoexcept |
Get an const-iterator to the first item in the vector.
|
inlinenoexcept |
Get an const-iterator beyond the last item in the vector.
|
inlinenoexcept |
Remove all items from the vector.
The allocation of the items remains.
|
inlinenoexcept |
Get a const-pointer to the first item.
|
inlinenoexcept |
Get a pointer to the first item.
|
inline |
Construct in-place a new item.
If the item is not placed at the end, the item will be moved to the correct position after it is created at the end.
pos | The position where the item will be created. |
args | The arguments to pass to the constructor of the new item. |
|
inline |
In-place construct an item at the end of the vector.
The item is directly constructed at the end of the vector.
args | The arguments passed to the constructor. |
|
inlineconstexprnoexcept |
Check if the vector is empty.
true | The vector is empty. |
false | The vector contains at least one item. |
|
inlinenoexcept |
Get an const-iterator beyond the last item in the vector.
|
inlinenoexcept |
Get an iterator beyond the last item in the vector.
|
inline |
Erase an items.
Erases an items between first and last. Items beyond the position will be moved.
This function will not change the allocation and iterators up to the erased items remain valid.
first | An iterator pointing to the first item to be removed. |
last | An iterator pointing beyond the last item to be removed. |
|
inline |
Erase an item at position.
Erases an item at a position. Items beyond the position will be moved.
This function will not change the allocation and iterators up to the erased item remain valid.
pos | An iterator pointing to the item to be removed. |
|
inlinenoexcept |
Get a const-reference to the first item in the vector.
|
inlinenoexcept |
Get a reference to the first item in the vector.
|
inlineconstexprnoexcept |
The allocator_type used to allocate items.
|
inline |
Insert new items.
If the items are not placed at the end, the items will be moved to the correct position after they have been copied to the end.
pos | The position where the items will be inserted. |
first | An iterator to the first item to copy. |
last | An iterator to one beyond the last item to copy. |
|
inline |
Insert a new item.
If the item is not placed at the end, the item will be moved to the correct position after it is moved to the end.
pos | The position where the item will be inserted. |
count | The number of value to add. |
value | The value to move into the vector. |
|
inline |
Insert new items.
If the items are not placed at the end, the items will be moved to the correct position after they have been copied to the end.
pos | The position where the items will be inserted. |
list | A initializer list of items to copy into the vector. |
|
inline |
Insert a new item.
If the item is not placed at the end, the item will be moved to the correct position after it is moved to the end.
pos | The position where the item will be inserted. |
value | The value to move into the vector. |
|
inline |
Insert a new item.
If the item is not placed at the end, the item will be moved to the correct position after it is copied to the end.
pos | The position where the item will be inserted. |
value | The value to copy into the vector. |
|
inlinenoexcept |
Move-assign a vector.
This will swap the allocations between the current and other vector. Or this will destroy the items in the current vector, then copy the items from other, potentially reusing the current allocation.
other | The vector to move. |
|
inlinenoexcept |
Copy-assign a vector.
This will destroy the items in the current vector, then copy the items from other, potentially reusing the current allocation.
other | The vector to copy. |
|
inlinenoexcept |
Get a const-reference to an item in the vector.
index | The index to the item in the vector. |
|
inlinenoexcept |
Get a reference to an item in the vector.
index | The index to the item in the vector. |
|
inline |
Remove the last item from the vector.
This function destroys the last item from the vector.
|
inline |
Move an item to the end of the vector.
value | The value to move to the vector. |
|
inline |
Copy an item to the end of the vector.
value | The value to copy to the vector. |
|
inline |
Reserve capacity for items.
This will create a new allocation when new_capacity is larger than the current capacity and move the items from the previous allocation.
new_capacity | The new capacity that the vector should take. |
|
inline |
Resize a vector.
When the new_size is larger than the current size a new allocation may be created and the new-items beyond the old size are default constructed.
When the new_size is smaller than the current size the allocation remains and the old-items beyond new_size are destroyed.
new_size | The new size of the vector. |
|
inline |
Resize a vector.
When the new_size is larger than the current size a new allocation may be created and the new-items beyond the old size are copied from value.
When the new_size is smaller than the current size the allocation remains and the old-items beyond new_size are destroyed.
new_size | The new size of the vector. |
value | The value of the items being optionally created. |
|
inlineconstexprnoexcept |
The maximum number of items that can fit without allocation.
|
inline |
Shrink the allocation to fit the current number of items.
If the current allocation is larger than the number of items in the vector, then a new allocation is created to exactly fit the number of items and the items are moved to the new allocation.
|
inlineconstexprnoexcept |
Get the number of items in the vector.
|
friend |
Erase items of a value from a vector.
c | The vector with items |
pred | A predicate function of the form bool(value_type const &) . |
|
friend |
Erase items of a value from a vector.
c | The vector with items |
value | The value to remove from the vector. |
|
friend |
Compare two vectors lexicographically.
lhs | The left-hand-side vector. |
rhs | The right-hand-side vector. |
|
friend |
Compare two vectors.
lhs | The left-hand-side vector. |
rhs | The right-hand-side vector. |
true | If both vectors contain the same items. |