|
libhatchet
|
#include <hxvector.hpp>
Public Types | |
| using | iterator = T* |
| using | const_iterator = const T* |
| using | value_type = T |
Public Member Functions | |
| hxvector (void) | |
| hxvector (hxsize_t size_) noexcept | |
| hxvector (hxsize_t size_, const T &x_) noexcept | |
| hxvector (const hxvector &x_) noexcept | |
| template<hxsize_t capacity_x_> | |
| hxvector (const hxvector< T, capacity_x_ > &x_) noexcept | |
| hxvector (hxvector &&x_) noexcept | |
| template<typename other_value_t_, hxsize_t array_length_> | |
| hxvector (const other_value_t_(&array_)[array_length_]) noexcept | |
| template<typename other_value_t_> | |
| hxvector (std::initializer_list< other_value_t_ > x_) noexcept | |
| ~hxvector (void) noexcept | |
| void | operator= (const hxvector &x_) noexcept |
| template<hxsize_t capacity_x_> | |
| void | operator= (const hxvector< T, capacity_x_ > &x_) noexcept |
| void | operator= (hxvector &&x_) noexcept |
| template<typename other_value_t_, hxsize_t array_length_> | |
| void | operator= (const other_value_t_(&array_)[array_length_]) noexcept |
| const T & | operator[] (hxsize_t index_) const |
| T & | operator[] (hxsize_t index_) |
| void | operator+= (const T &x_) noexcept |
| void | operator+= (T &&x_) noexcept |
| template<hxsize_t capacity_x_> | |
| void | operator+= (const hxvector< T, capacity_x_ > &x_) noexcept |
| template<hxsize_t capacity_x_> | |
| void | operator+= (hxvector< T, capacity_x_ > &&x_) noexcept |
| hxarray_back_inserter_< hxvector< T, capacity_ > > | operator* (void) |
| hxvector & | operator++ (void) |
| hxvector & | operator++ (int) |
| template<typename callable_t_> | |
| bool | all_of (callable_t_ &&callable_) const |
| template<typename callable_t_> | |
| bool | all_of (callable_t_ &&callable_) |
| template<typename callable_t_> | |
| bool | any_of (callable_t_ &&callable_) const |
| template<typename callable_t_> | |
| bool | any_of (callable_t_ &&callable_) |
| template<typename iter_t_> | |
| void | assign (iter_t_ begin_, iter_t_ end_) noexcept |
| template<typename range_t_> | |
| void | assign_range (range_t_ &range_) noexcept |
| template<typename range_t_> requires (!hxis_lvalue_reference<range_t_>::value) | |
| void | assign_range (range_t_ &&range_) noexcept |
| const T & | back (void) const |
| T & | back (void) |
| const T * | begin (void) const |
| T * | begin (void) |
| const T * | binary_search (const T &value_) const |
| T * | binary_search (const T &value_) |
| hxsize_t | capacity (void) const |
| const T * | cbegin (void) const |
| const T * | cend (void) const |
| void | clear (void) noexcept |
| template<typename... args_t_> | |
| T & | emplace_back (args_t_ &&... args_) noexcept |
| template<hxsize_t capacity_x_> | |
| bool | equal (const hxvector< T, capacity_x_ > &x_) const |
| bool | empty (void) const |
| const T * | end (void) const |
| T * | end (void) |
| void | erase (T *pos_) noexcept |
| void | erase (hxsize_t index_) noexcept |
| template<typename callable_t_> | |
| hxsize_t | erase_if_unordered (callable_t_ &&callable_) noexcept |
| template<typename callable_t_> | |
| hxsize_t | erase_if_heap (callable_t_ &&callable_) noexcept |
| void | erase_unordered (const T *pos_) noexcept |
| void | erase_unordered (hxsize_t index_) noexcept |
| const T * | find (const T &value_) const |
| T * | find (const T &value_) |
| template<typename callable_t_> | |
| const T * | find_if (callable_t_ &&callable_) const |
| template<typename callable_t_> | |
| T * | find_if (callable_t_ &&callable_) |
| template<typename callable_t_> | |
| void | for_each (callable_t_ &&callable_) const |
| template<typename callable_t_> | |
| void | for_each (callable_t_ &&callable_) |
| const T & | front (void) const |
| T & | front (void) |
| bool | full (void) const |
| template<typename callable_t_> | |
| void | generate_n (hxsize_t size_, callable_t_ &&callable_) noexcept |
| const T * | get (hxsize_t index_) const |
| T * | get (hxsize_t index_) |
| template<typename ref_t_> | |
| void | insert (const T *pos_, ref_t_ &&x_) noexcept |
| template<typename ref_t_> | |
| void | insert (hxsize_t index_, ref_t_ &&x_) noexcept |
| void | insertion_sort (void) noexcept |
| template<hxsize_t capacity_x_> | |
| bool | less (const hxvector< T, capacity_x_ > &x_) const |
| void | make_heap (void) noexcept |
| hxsize_t | max_size (void) const |
| template<hxsize_t capacity_x_> | |
| void | memcpy (const hxvector< T, capacity_x_ > &x_) |
| void | memset (int byte_=0x00) |
| void | pop_back (void) noexcept |
| void | pop_heap (void) noexcept |
| template<typename... args_t_> | |
| T & | push_back (args_t_ &&... args_) noexcept |
| template<typename ref_t_> | |
| T & | push_heap (ref_t_ &&arg_) noexcept |
| void | reserve (hxsize_t size_, hxsystem_allocator_t allocator_=hxsystem_allocator_current, hxalignment_t alignment_=hxalignment) |
| void | resize (hxsize_t size_) noexcept |
| void | resize (hxsize_t size_, const T &x_) noexcept |
| hxsize_t | size (void) const |
| hxsize_t | size_bytes (void) const |
| void | sort (void) noexcept |
| void | swap (hxvector &x_) noexcept |
hxvector - Implements std::vector, std::inplace_vector and std::back_insert_iterator with a few things added and a few things unimplemented.
Uses raw pointers as an iterator type so that you get compile errors and debug symbols that use plain C++ pointers instead. There are exhaustive asserts. hxvector uses the hxkey_less and hxkey_equal overloads. They default to using operators < and ==. See hxalgorithm.hpp for callable versions of the algorithms here.
hxvector can be constructed from C string literals as follows: hxvector<char, HX_MAX_LINE> string_buffer("example C string"); however operator+= does not support C strings.
Please run both a memory sanitizer and an undefined behavior sanitizer. Use a C array for now if you need constexpr support. The C++ standard made special provisions for std::vector that were not made for this class. The excessive number of operators is due to the rules about default operators.
| using hxvector< T, capacity_ >::const_iterator = const T* |
Const random access iterator.
| using hxvector< T, capacity_ >::iterator = T* |
Random access iterator.
| using hxvector< T, capacity_ >::value_type = T |
Publishes the value type. Doesn't end with _t because of the standard.
|
explicit |
|
explicitnoexcept |
Constructs an array of a given size using T's default constructor.
|
explicitnoexcept |
Constructs an array of a given size by making copies of x.
|
noexcept |
|
noexcept |
Copy constructs an array.
Non-explicit to allow assignment constructor.
|
noexcept |
Copy construct from a temporary.
Refuses to copy construct from a statically allocated temporary for efficiency. Only works with hxallocator_dynamic_capacity.
|
noexcept |
Constructs from a C-style array.
Usable as an initializer_list when the std namespace is not available. e.g.,
|
noexcept |
Pass values of std::initializer_list as initializers to an array of T.
WARNING: This constructor will override the other constructors when uniform initialization is used. e.g., hxvector<int> x{1, 2} is an array containing {1, 2} and hxvector<int> x(1, 2) is the array containing {2}.
|
noexcept |
Destructs the array and destroys all elements.
| bool hxvector< T, capacity_ >::all_of | ( | callable_t_ && | callable_ | ) |
A non-const version of all_of.
| bool hxvector< T, capacity_ >::all_of | ( | callable_t_ && | callable_ | ) | const |
Returns true if the predicate returns true for every element and false otherwise.
Will stop iterating when the predicate returns false. e.g.,
| bool hxvector< T, capacity_ >::any_of | ( | callable_t_ && | callable_ | ) |
A non-const version of any_of.
| bool hxvector< T, capacity_ >::any_of | ( | callable_t_ && | callable_ | ) | const |
Returns true if the predicate returns true for any element and false otherwise.
Will stop iterating when the predicate returns true. e.g.,
|
noexcept |
|
noexcept |
Assigns elements from a temporary range.
This overload enables moving the range elements into the array when forwarding rvalues.
|
noexcept |
Assigns elements from a range referenced by an lvalue.
range_t::begin and range_t::end are required as std::begin and std::end may not exist. Use operator= to assign from a C-style array.
| T & hxvector< T, capacity_ >::back | ( | void | ) |
Returns a reference to the last element in the array.
| const T & hxvector< T, capacity_ >::back | ( | void | ) | const |
Returns a const reference to the last element in the array.
|
inline |
Returns a T* to the beginning of the array.
|
inline |
Returns a const T* to the beginning of the array.
| T * hxvector< T, capacity_ >::binary_search | ( | const T & | value_ | ) |
Non-const version.
Performs a binary search using hxkey_less. Returns end when not found.
| const T * hxvector< T, capacity_ >::binary_search | ( | const T & | value_ | ) | const |
Performs a binary search using hxkey_less.
Returns end() when not found.
| hxsize_t hxvector< T, capacity_ >::capacity | ( | void | ) | const |
Returns the capacity of the array or 0 if unallocated.
|
inline |
Returns a const T* to the beginning of the array (alias for begin).
|
inline |
Returns a const T* to the end of the array.
|
noexcept |
Clears the array, destroying all elements.
|
noexcept |
Emplaces an element at the end of the array using forwarded arguments.
Returns a reference to the new element. Exactly the same as push_back.
|
inline |
Returns true if the array is empty.
Callers must check the return value instead of discarding it.
|
inline |
Returns a T* to the end of the array.
|
inline |
Returns a const T* to the end of the array.
| bool hxvector< T, capacity_ >::equal | ( | const hxvector< T, capacity_x_ > & | x_ | ) | const |
Returns true if the arrays compare equivalent using hxkey_equal.
Callers must check the return value to detect mismatches.
|
noexcept |
Erases the element indicated.
Use (hxsize_t)0 to write the integer literal 0.
|
noexcept |
Erases the element indicated.
Should not compile with hxnull. Support for erasing ranges has not been added yet.
|
noexcept |
Removes elements for which the predicate returns true while preserving the max-heap property maintained by push_heap/pop_heap.
Returns the number of erased elements. e.g.,
|
noexcept |
Removes elements for which the predicate returns true.
(Non-standard.) Equivalent to calling erase_unordered inside a reverse loop. Returns the number of erased elements. e.g.,
|
noexcept |
Variant of erase that moves the end element down to replace the erased element.
Should not compile with hxnull. (Non-standard.) Can be used to erase elements of an array as it is traversed as follows:
|
noexcept |
| T * hxvector< T, capacity_ >::find | ( | const T & | value_ | ) |
Non-const version of find using hxkey_equal.
| const T * hxvector< T, capacity_ >::find | ( | const T & | value_ | ) | const |
Finds the first occurrence of value using hxkey_equal.
Returns end if no element matches.
| T * hxvector< T, capacity_ >::find_if | ( | callable_t_ && | callable_ | ) |
Non-const version of find_if.
| const T * hxvector< T, capacity_ >::find_if | ( | callable_t_ && | callable_ | ) | const |
Finds the first element for which the predicate returns true.
Returns end if no element matches. e.g.,
| void hxvector< T, capacity_ >::for_each | ( | callable_t_ && | callable_ | ) |
Non-const version of for_each.
| void hxvector< T, capacity_ >::for_each | ( | callable_t_ && | callable_ | ) | const |
Calls a function, lambda, or std::function on each element.
(Non-standard.) Lambdas and std::function instances can be provided as temporaries, so that has to be allowed. The && variant of callable_t::operator() may be selected using hxmove. This is the standard way to signal to the callable that it is a temporary. e.g.,
| T & hxvector< T, capacity_ >::front | ( | void | ) |
Returns a reference to the first element in the array.
| const T & hxvector< T, capacity_ >::front | ( | void | ) | const |
Returns a const reference to the first element in the array.
|
inline |
Returns true when the array is full (size equals capacity).
(Non-standard.) Callers must check the return value before adding more elements.
|
noexcept |
| T * hxvector< T, capacity_ >::get | ( | hxsize_t | index_ | ) |
Returns a T* to the element at index or hxnull otherwise.
| const T * hxvector< T, capacity_ >::get | ( | hxsize_t | index_ | ) | const |
Returns a const T* to the element at index or hxnull otherwise.
|
noexcept |
Inserts the element at the offset indicated.
Should not compile with hxnull. insert(begin(), x) and insert(end(), x) will work as long as the array is allocated. Not intended for objects that are expensive to move. Support for inserting ranges has not been added yet. Consider using emplace_back for storing large objects.
|
noexcept |
Inserts the element at the offset indicated.
Use (hxsize_t)0 to write the integer literal 0. insert(begin(), x) and insert(end(), x) will work as long as the array is allocated.
|
noexcept |
Sorts the array with insertion sort using hxkey_less. (Non-standard.).
| bool hxvector< T, capacity_ >::less | ( | const hxvector< T, capacity_x_ > & | x_ | ) | const |
Returns true if this array compares less than x using hxkey_equal and hxkey_less.
Sorts [1] before [1, 2]. Callers must check the return value to observe the ordering result.
|
noexcept |
Converts the array into a max-heap using hxkey_less. (Non-standard.).
|
inline |
Returns the capacity of the array or 0 if unallocated.
This is the standard way to report that reallocation is not allowed.
| void hxvector< T, capacity_ >::memcpy | ( | const hxvector< T, capacity_x_ > & | x_ | ) |
| void hxvector< T, capacity_ >::memset | ( | int | byte_ = 0x00 | ) |
Calls memset on the array.
The default fill byte is 0x00.
| hxarray_back_inserter_< hxvector< T, capacity_ > > hxvector< T, capacity_ >::operator* | ( | void | ) |
Used to write code with pointer semantics that writes to either a pointer or a hxvector.
Allows an array to be passed as a reference and then used as an output iterator similar to std::back_insert_iterator. This operator is used to grow the array while operator++ is ignored. Uses a single call to placement new when copying.
|
inline |
Postfix version.
|
inline |
Allows an array to be passed as a reference and then used as an output iterator similar to std::back_insert_iterator.
This operator doesn't do anything but allow the container to be used with pointer sematics. See hxalgorithm.hpp for usage.
|
noexcept |
Appends the contents of another array.
(Non-standard, from Python.) Vector math is not a goal so this should not end up overloaded.
|
noexcept |
Appends an element.
(Non-standard.) Vector math is not a goal so this should not end up overloaded. Perfect argument forwarding would be too ambiguous.
|
noexcept |
Appends the contents of another array.
(Non-standard, from Python.) Vector math is not a goal so this should not end up overloaded.
|
noexcept |
Appends an element.
(Non-standard.) Vector math is not a goal so this should not end up overloaded. Perfect argument forwarding would be too ambiguous.
|
noexcept |
|
noexcept |
|
noexcept |
Assign from a C-style array.
Usable as an initializer_list when the std namespace is not available. e.g.,
|
noexcept |
Swap contents with a temporary array using swap.
Only works with hxallocator_dynamic_capacity. Dynamically allocated arrays are swapped with very little overhead.
| T & hxvector< T, capacity_ >::operator[] | ( | hxsize_t | index_ | ) |
Returns a reference to the element at the specified index.
| const T & hxvector< T, capacity_ >::operator[] | ( | hxsize_t | index_ | ) | const |
Returns a const reference to the element at the specified index.
|
noexcept |
Removes the end element from the array.
|
noexcept |
Removes the first (maximum) element from a max-heap.
This implements std::pop_heap and std::priority_queue using hxkey_less for ordering. See push_heap.
|
noexcept |
Appends an element to the end of the array.
args_t may be any types that can be used to construct T. Returns a reference to the new element. Exactly the same as emplace_back.
|
noexcept |
Inserts an element into a max-heap.
This implements std::push_heap and std::priority_queue using hxkey_less for ordering. See pop_heap. Returns a reference to the element added.
| void hxvector< T, capacity_ >::reserve | ( | hxsize_t | size_, |
| hxsystem_allocator_t | allocator_ = hxsystem_allocator_current, | ||
| hxalignment_t | alignment_ = hxalignment ) |
Reserves storage for at least the specified number of elements.
|
noexcept |
Resizes the array to the specified size, constructing or destroying elements as needed.
Requires a default constructor. New elements are default-initialized, leaving integers and floats uninitialized.
|
noexcept |
An overload with an initial value for new elements.
Resizes the array to the specified size, copy constructing or destroying elements as needed.
|
inline |
Returns the number of elements in the array.
|
inline |
Returns the number of bytes in the array. (Non-standard.).
|
noexcept |
Sorts the array using hxkey_less. (Non-standard.).
|
noexcept |
Swap contents with a temporary array.
Only works with hxallocator_dynamic_capacity. Dynamically allocated arrays are swapped with very little overhead.