libhatchet
Loading...
Searching...
No Matches
hxvector< T, capacity_ > Class Template Reference

#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)
hxvectoroperator++ (void)
hxvectoroperator++ (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

Detailed Description

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
class hxvector< T, capacity_ >

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.

Member Typedef Documentation

◆ const_iterator

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxvector< T, capacity_ >::const_iterator = const T*

Const random access iterator.

◆ iterator

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxvector< T, capacity_ >::iterator = T*

Random access iterator.

◆ value_type

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxvector< T, capacity_ >::value_type = T

Publishes the value type. Doesn't end with _t because of the standard.

Constructor & Destructor Documentation

◆ hxvector() [1/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector< T, capacity_ >::hxvector ( void )
explicit

Constructs an empty array with a capacity of capacity.

m_end_ will be 0 if capacity is 0.

◆ hxvector() [2/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector< T, capacity_ >::hxvector ( hxsize_t size_)
explicitnoexcept

Constructs an array of a given size using T's default constructor.

  • size : Sets array size as if resize(size) were called.

◆ hxvector() [3/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector< T, capacity_ >::hxvector ( hxsize_t size_,
const T & x_ )
explicitnoexcept

Constructs an array of a given size by making copies of x.

  • size : Sets array size as if resize(size, x) were called.
  • x : The const T& to be duplicated.

◆ hxvector() [4/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector< T, capacity_ >::hxvector ( const hxvector< T, capacity_ > & x_)
noexcept

Copy constructs an array.

Non-explicit to allow assignment constructor.

◆ hxvector() [5/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
hxvector< T, capacity_ >::hxvector ( const hxvector< T, capacity_x_ > & x_)
noexcept

Copy constructs an array.

Non-explicit to allow assignment constructor.

◆ hxvector() [6/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector< T, capacity_ >::hxvector ( hxvector< T, capacity_ > && x_)
noexcept

Copy construct from a temporary.

Refuses to copy construct from a statically allocated temporary for efficiency. Only works with hxallocator_dynamic_capacity.

◆ hxvector() [7/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename other_value_t_, hxsize_t array_length_>
hxvector< T, capacity_ >::hxvector ( const other_value_t_(&) array_[array_length_])
noexcept

Constructs from a C-style array.

Usable as an initializer_list when the std namespace is not available. e.g.,

static const int initial_values[] = { 5, 4, 3 };
hxvector<int, 32> current_values(initial_values);
hxvector - Implements std::vector, std::inplace_vector and std::back_insert_iterator with a few thing...
Definition hxvector.hpp:82
  • array : A const array of array_length_ value_type.

◆ hxvector() [8/8]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename other_value_t_>
hxvector< T, capacity_ >::hxvector ( std::initializer_list< other_value_t_ > x_)
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}.

  • x : A std::initializer_list<other_value_t>.

◆ ~hxvector()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector< T, capacity_ >::~hxvector ( void )
noexcept

Destructs the array and destroys all elements.

Member Function Documentation

◆ all_of() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
bool hxvector< T, capacity_ >::all_of ( callable_t_ && callable_)

A non-const version of all_of.

◆ all_of() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
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.,

// Assert an array of ints contains all 10s.
EXPECT_TRUE(ints.all_of([&](const int& value) -> bool {
return value == 10;
}));
#define EXPECT_TRUE(x_)
void EXPECT_TRUE(bool) - Requires that the condition is true.
Definition hxtest.hpp:180
  • callable : A callable returning boolean. !all_of(x) -> any_not(x).

◆ any_of() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
bool hxvector< T, capacity_ >::any_of ( callable_t_ && callable_)

A non-const version of any_of.

◆ any_of() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
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.,

// Assert an array of ints contains at least one 10.
EXPECT_TRUE(ints.any_of([&](const int& value) -> bool {
return value == 10;
}));
  • callable : A callable returning boolean. !any_of(x) -> none_of(x).

◆ assign()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename iter_t_>
void hxvector< T, capacity_ >::assign ( iter_t_ begin_,
iter_t_ end_ )
noexcept

Assigns elements from a range defined by random access iterators.

iter_t::operator- is required.

  • begin : The beginning iterator.
  • end : The end iterator.

◆ assign_range() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename range_t_>
requires (!hxis_lvalue_reference<range_t_>::value)
void hxvector< T, capacity_ >::assign_range ( range_t_ && range_)
noexcept

Assigns elements from a temporary range.

This overload enables moving the range elements into the array when forwarding rvalues.

  • range : The range to move elements from.

◆ assign_range() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename range_t_>
void hxvector< T, capacity_ >::assign_range ( range_t_ & range_)
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.

  • range : The range to copy elements from.

◆ back() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T & hxvector< T, capacity_ >::back ( void )

Returns a reference to the last element in the array.

◆ back() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T & hxvector< T, capacity_ >::back ( void ) const

Returns a const reference to the last element in the array.

◆ begin() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T * hxvector< T, capacity_ >::begin ( void )
inline

Returns a T* to the beginning of the array.

◆ begin() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxvector< T, capacity_ >::begin ( void ) const
inline

Returns a const T* to the beginning of the array.

◆ binary_search() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T * hxvector< T, capacity_ >::binary_search ( const T & value_)

Non-const version.

Performs a binary search using hxkey_less. Returns end when not found.

  • value : The value to locate.

◆ binary_search() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxvector< T, capacity_ >::binary_search ( const T & value_) const

Performs a binary search using hxkey_less.

Returns end() when not found.

  • value : The value to locate.

◆ capacity()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxvector< T, capacity_ >::capacity ( void ) const

Returns the capacity of the array or 0 if unallocated.

◆ cbegin()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxvector< T, capacity_ >::cbegin ( void ) const
inline

Returns a const T* to the beginning of the array (alias for begin).

◆ cend()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxvector< T, capacity_ >::cend ( void ) const
inline

Returns a const T* to the end of the array.

◆ clear()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::clear ( void )
noexcept

Clears the array, destroying all elements.

◆ emplace_back()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename... args_t_>
T & hxvector< T, capacity_ >::emplace_back ( args_t_ &&... args_)
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.

  • args : Arguments forwarded to T's constructor.

◆ empty()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
bool hxvector< T, capacity_ >::empty ( void ) const
inline

Returns true if the array is empty.

Callers must check the return value instead of discarding it.

◆ end() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T * hxvector< T, capacity_ >::end ( void )
inline

Returns a T* to the end of the array.

◆ end() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxvector< T, capacity_ >::end ( void ) const
inline

Returns a const T* to the end of the array.

◆ equal()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
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.

  • x : The other array.

◆ erase() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::erase ( hxsize_t index_)
noexcept

Erases the element indicated.

Use (hxsize_t)0 to write the integer literal 0.

  • index : Index of the element to erase.

◆ erase() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::erase ( T * pos_)
noexcept

Erases the element indicated.

Should not compile with hxnull. Support for erasing ranges has not been added yet.

  • pos : Non-null pointer to an element currently stored in the array.

◆ erase_if_heap()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
hxsize_t hxvector< T, capacity_ >::erase_if_heap ( callable_t_ && callable_)
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.,

// Erase all the 10s in a heap.
ints.erase_if_heap([](const int& value) -> bool { return value == 10; });
  • callable : A callable returning boolean.

◆ erase_if_unordered()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
hxsize_t hxvector< T, capacity_ >::erase_if_unordered ( callable_t_ && callable_)
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.,

// Erase all the 10s in an array.
ints.erase_if_unordered([](const int& value) -> bool { return value == 10; });
  • callable : A callable returning boolean.

◆ erase_unordered() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::erase_unordered ( const T * pos_)
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:

for(hxsize_t i = a.size(); i--; ) {
if(should_erase(a[i])) {
a.erase_unordered(i);
}
}
ptrdiff_t hxsize_t
hxsize_t - A signed size type, same as ssize_t or ptrdiff_t.
Definition libhatchet.h:209
  • pos : Non-null pointer to an element currently stored in the array.

◆ erase_unordered() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::erase_unordered ( hxsize_t index_)
noexcept

Variant of erase that moves the end element down to replace the erased element.

Use (hxsize_t)0 to write the integer literal 0. (Non-standard.)

  • index : The index of the element to erase.

◆ find() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T * hxvector< T, capacity_ >::find ( const T & value_)

Non-const version of find using hxkey_equal.

  • value : The value to locate.

◆ find() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
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.

  • value : The value to locate.

◆ find_if() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
T * hxvector< T, capacity_ >::find_if ( callable_t_ && callable_)

Non-const version of find_if.

◆ find_if() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
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.,

// Search for a 10 and check if it was found.
if(int* t = ints.find_if([](int& x) { return x == 10; }); t != ints.end()) {
// ... Process the 10.
}
  • callable : A callable returning boolean.

◆ for_each() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
void hxvector< T, capacity_ >::for_each ( callable_t_ && callable_)

Non-const version of for_each.

◆ for_each() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
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.,

hxvector<int> a(3, 0);
a.for_each([](int& x) { ++x; }); // Produces { 1, 1, 1 }.
hxvector(void)
Constructs an empty array with a capacity of capacity.
  • callable : A callable.

◆ front() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T & hxvector< T, capacity_ >::front ( void )

Returns a reference to the first element in the array.

◆ front() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T & hxvector< T, capacity_ >::front ( void ) const

Returns a const reference to the first element in the array.

◆ full()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
bool hxvector< T, capacity_ >::full ( void ) const
inline

Returns true when the array is full (size equals capacity).

(Non-standard.) Callers must check the return value before adding more elements.

◆ generate_n()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
void hxvector< T, capacity_ >::generate_n ( hxsize_t size_,
callable_t_ && callable_ )
noexcept

Appends size elements generated by invoking callable repeatedly.

  • size : Number of elements to append.
  • callable : callable returning the elements to append.

◆ get() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T * hxvector< T, capacity_ >::get ( hxsize_t index_)

Returns a T* to the element at index or hxnull otherwise.

  • index : The 0-based offset of the element.

◆ get() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxvector< T, capacity_ >::get ( hxsize_t index_) const

Returns a const T* to the element at index or hxnull otherwise.

  • index : The 0-based offset of the element.

◆ insert() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename ref_t_>
void hxvector< T, capacity_ >::insert ( const T * pos_,
ref_t_ && x_ )
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.

  • pos : Non-null pointer to the location where the new element will be inserted. Must point inside or one past the current range.
  • x : The new element.

◆ insert() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename ref_t_>
void hxvector< T, capacity_ >::insert ( hxsize_t index_,
ref_t_ && x_ )
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.

  • index : Index of the location where the new element will be inserted.
  • x : The new element.

◆ insertion_sort()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::insertion_sort ( void )
noexcept

Sorts the array with insertion sort using hxkey_less. (Non-standard.).

◆ less()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
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.

  • x : The other array.

◆ make_heap()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::make_heap ( void )
noexcept

Converts the array into a max-heap using hxkey_less. (Non-standard.).

◆ max_size()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxvector< T, capacity_ >::max_size ( void ) const
inline

Returns the capacity of the array or 0 if unallocated.

This is the standard way to report that reallocation is not allowed.

◆ memcpy()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
void hxvector< T, capacity_ >::memcpy ( const hxvector< T, capacity_x_ > & x_)

Copies another hxvector using memcpy.

  • x : The other array.

◆ memset()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::memset ( int byte_ = 0x00)

Calls memset on the array.

The default fill byte is 0x00.

  • byte : The byte that is repeated. May be a negative char value.

◆ operator*()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
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.

◆ operator++() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector & hxvector< T, capacity_ >::operator++ ( int )
inline

Postfix version.

◆ operator++() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxvector & hxvector< T, capacity_ >::operator++ ( void )
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.

◆ operator+=() [1/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
void hxvector< T, capacity_ >::operator+= ( const hxvector< T, capacity_x_ > & x_)
noexcept

Appends the contents of another array.

(Non-standard, from Python.) Vector math is not a goal so this should not end up overloaded.

  • x : Another array. Not a temporary.

◆ operator+=() [2/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::operator+= ( const T & x_)
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.

  • x : An object to append. Not a temporary.

◆ operator+=() [3/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
void hxvector< T, capacity_ >::operator+= ( hxvector< T, capacity_x_ > && x_)
noexcept

Appends the contents of another array.

(Non-standard, from Python.) Vector math is not a goal so this should not end up overloaded.

  • x : Another array passed as a temporary.

◆ operator+=() [4/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::operator+= ( T && x_)
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.

  • x : An object to append. Passed as a temporary.

◆ operator=() [1/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::operator= ( const hxvector< T, capacity_ > & x_)
noexcept

Assigns the contents of another hxvector to this array.

Standard except reallocation is disallowed.

◆ operator=() [2/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxsize_t capacity_x_>
void hxvector< T, capacity_ >::operator= ( const hxvector< T, capacity_x_ > & x_)
noexcept

Assigns the contents of another hxvector to this array.

Standard except reallocation is disallowed.

◆ operator=() [3/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename other_value_t_, hxsize_t array_length_>
void hxvector< T, capacity_ >::operator= ( const other_value_t_(&) array_[array_length_])
noexcept

Assign from a C-style array.

Usable as an initializer_list when the std namespace is not available. e.g.,

static const int initial_values[] = { 5, 4, 3 };
hxvector<int, 32> current_values(initial_values);
  • array : A const array of array_length value_type.

◆ operator=() [4/4]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::operator= ( hxvector< T, capacity_ > && x_)
noexcept

Swap contents with a temporary array using swap.

Only works with hxallocator_dynamic_capacity. Dynamically allocated arrays are swapped with very little overhead.

◆ operator[]() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
T & hxvector< T, capacity_ >::operator[] ( hxsize_t index_)

Returns a reference to the element at the specified index.

  • index : The 0-based offset of the element.

◆ operator[]() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T & hxvector< T, capacity_ >::operator[] ( hxsize_t index_) const

Returns a const reference to the element at the specified index.

  • index : The 0-based offset of the element.

◆ pop_back()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::pop_back ( void )
noexcept

Removes the end element from the array.

◆ pop_heap()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::pop_heap ( void )
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.

◆ push_back()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename... args_t_>
T & hxvector< T, capacity_ >::push_back ( args_t_ &&... args_)
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.

  • args : Arguments forwarded to T's constructor.

◆ push_heap()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename ref_t_>
T & hxvector< T, capacity_ >::push_heap ( ref_t_ && arg_)
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.

  • arg : The element to add.

◆ reserve()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
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.

  • size : The number of elements to reserve storage for.
  • allocator : The memory manager ID to use for allocation (default: hxsystem_allocator_current)
  • alignment : The alignment for the allocation. (default: hxalignment)

◆ resize() [1/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::resize ( hxsize_t size_)
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.

  • size : The new size of the array.

◆ resize() [2/2]

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::resize ( hxsize_t size_,
const T & x_ )
noexcept

An overload with an initial value for new elements.

Resizes the array to the specified size, copy constructing or destroying elements as needed.

  • size : The new size of the array.
  • x : Initial value for new elements.

◆ size()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxvector< T, capacity_ >::size ( void ) const
inline

Returns the number of elements in the array.

◆ size_bytes()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxvector< T, capacity_ >::size_bytes ( void ) const
inline

Returns the number of bytes in the array. (Non-standard.).

◆ sort()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::sort ( void )
noexcept

Sorts the array using hxkey_less. (Non-standard.).

◆ swap()

template<hxvector_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxvector< T, capacity_ >::swap ( hxvector< T, capacity_ > & x_)
noexcept

Swap contents with a temporary array.

Only works with hxallocator_dynamic_capacity. Dynamically allocated arrays are swapped with very little overhead.

  • x : The array to swap with.

The documentation for this class was generated from the following file: