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

#include <hxarray.hpp>

Public Types

using iterator = T*
using const_iterator = const T*
using value_t = T

Public Member Functions

 hxarray (void) noexcept
 hxarray (const T &x_) noexcept
 hxarray (const hxarray &x_) noexcept
 hxarray (hxarray &&x_) noexcept
template<typename other_value_t_, hxsize_t array_length_>
 hxarray (const other_value_t_(&array_)[array_length_]) noexcept
template<typename other_value_t_>
 hxarray (std::initializer_list< other_value_t_ > x_) noexcept
template<hxrange_concept_ range_t_>
requires (!hxis_same<hxremove_cvref_t<range_t_>, hxarray<T, capacity_> >())
 hxarray (range_t_ &range_) noexcept
template<hxrange_concept_ range_t_>
requires (!hxis_lvalue_reference<range_t_>() && !hxis_same<hxremove_cvref_t<range_t_>, hxarray<T, capacity_> >())
 hxarray (range_t_ &&range_) noexcept
 ~hxarray (void) noexcept
template<typename self_t_, typename callable_t_>
auto and_then (this self_t_ &&self_, hxsize_t index_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>
template<typename self_t_, typename callable_t_>
auto and_then (this self_t_ &&self_, const T *it_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< const T & >())))>
void operator= (const hxarray &x_) noexcept
void operator= (hxarray &&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_)
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_)
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
bool empty (void) const
const T * end (void) const
T * end (void)
bool equal (const hxarray &x_) const
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_)
bool full (void) const
template<typename callable_t_>
void for_each (callable_t_ &&callable_) const
template<typename callable_t_>
void for_each (callable_t_ &&callable_)
hxhash_t hash (void) const
void insertion_sort (void) noexcept
bool less (const hxarray &x_) const
hxsize_t max_size (void) const
void memcpy (const hxarray &x_)
void memset (int byte_=0x00)
template<typename self_t_, typename callable_t_>
auto or_else (this self_t_ &&self_, hxsize_t index_, callable_t_ &&callable_) -> decltype(self_.end())
template<typename self_t_, typename callable_t_>
auto or_else (this self_t_ &&self_, const T *it_, callable_t_ &&callable_) -> decltype(self_.end())
void reserve (hxsize_t size_, hxsystem_allocator_t allocator_=hxsystem_allocator_current, hxalignment_t alignment_=hxalignment) noexcept
hxsize_t size (void) const
hxsize_t size_bytes (void) const
void sort (void) noexcept
void swap (hxarray &x_) noexcept
template<typename self_t_, typename... args_t_>
T value_or (this self_t_ &&self_, hxsize_t index_, args_t_ &&... args_)
template<typename self_t_, typename... args_t_>
T value_or (this self_t_ &&self_, const T *it_, args_t_ &&... args_)

Detailed Description

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
class hxarray< T, capacity_ >

hxarray - Implements std::array with a few things added.

It also implements a dynamically allocated array that does not change size using hxallocator_dynamic_capacity which provides an optimization the standard does not. 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. hxarray uses the hxkey_less_t and hxkey_equal_t callables. They default to using operators < and ==. See hxrange.hpp for callable versions of the algorithms here.

Unlike hxvector, hxarray always has a fixed size equal to its capacity. Size-changing operations are not provided. Use hxvector when dynamic sizing is needed. When capacity is hxallocator_dynamic_capacity, storage must be allocated by calling reserve before use.

Member Typedef Documentation

◆ const_iterator

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxarray< T, capacity_ >::const_iterator = const T*

const_iterator - Const random access iterator.

◆ iterator

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxarray< T, capacity_ >::iterator = T*

iterator - Random access iterator.

◆ value_t

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxarray< T, capacity_ >::value_t = T

value_type - Publishes the value type.

Constructor & Destructor Documentation

◆ hxarray() [1/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxarray< T, capacity_ >::hxarray ( void )
explicitnoexcept

Default constructs all elements.

◆ hxarray() [2/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxarray< T, capacity_ >::hxarray ( const T & x_)
explicitnoexcept

Constructs all elements as copies of x.

  • x : The const T& to be duplicated.

◆ hxarray() [3/8]

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

Copy constructs from another hxarray of the same capacity.

◆ hxarray() [4/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxarray< T, capacity_ >::hxarray ( hxarray< T, capacity_ > && x_)
noexcept

Move constructs from a temporary hxarray.

Requires hxallocator_dynamic_capacity.

◆ hxarray() [5/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename other_value_t_, hxsize_t array_length_>
hxarray< T, capacity_ >::hxarray ( 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 };
hxarray<int, 3> current_values(initial_values);
hxarray - Implements std::array with a few things added.
Definition hxarray.hpp:52
  • array : A const array of exactly capacity elements.

◆ hxarray() [6/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename other_value_t_>
hxarray< T, capacity_ >::hxarray ( std::initializer_list< other_value_t_ > x_)
noexcept

Pass values of std::initializer_list as initializers.

  • x : A std::initializer_list<other_value_t> of exactly capacity elements.

◆ hxarray() [7/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxrange_concept_ range_t_>
requires (!hxis_same<hxremove_cvref_t<range_t_>, hxarray<T, capacity_> >())
hxarray< T, capacity_ >::hxarray ( range_t_ & range_)
explicitnoexcept

Constructs by copying elements from a range referenced by an lvalue.

  • range : A range of exactly capacity elements.

◆ hxarray() [8/8]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<hxrange_concept_ range_t_>
requires (!hxis_lvalue_reference<range_t_>() && !hxis_same<hxremove_cvref_t<range_t_>, hxarray<T, capacity_> >())
hxarray< T, capacity_ >::hxarray ( range_t_ && range_)
explicitnoexcept

Constructs by moving elements from a temporary range.

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

  • range : A temporary range of exactly capacity elements.

◆ ~hxarray()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxarray< T, capacity_ >::~hxarray ( void )
noexcept

Destructs the array and destroys all elements.

Member Function Documentation

◆ all_of() [1/2]

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

◆ all_of() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
bool hxarray< 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:170
  • callable : A callable returning boolean. !all_of(x) -> any_not(x).

◆ and_then() [1/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
auto hxarray< T, capacity_ >::and_then ( this self_t_ && self_,
const T * it_,
callable_t_ && callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< constT & >())))>

Iterator overload of and_then.

  • it : A const iterator to an element or end().
  • callable : The function to call with the element.

◆ and_then() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
auto hxarray< T, capacity_ >::and_then ( this self_t_ && self_,
hxsize_t index_,
callable_t_ && callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>

Returns the result of calling callable with the element at index, otherwise returns hxnil.

Use and_then to return hxptr, hxref or hxexpected.

  • index : The 0-based position of the element.
  • callable : The function to call with the element.

◆ any_of() [1/2]

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

◆ any_of() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
bool hxarray< 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).

◆ begin() [1/2]

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

◆ begin() [2/2]

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

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

◆ binary_search() [1/2]

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

◆ binary_search() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxarray< 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<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxarray< T, capacity_ >::capacity ( void ) const

Returns the capacity of the array.

◆ cbegin()

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

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

◆ cend()

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

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

◆ empty()

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

Returns true if the array contains no elements.

◆ end() [1/2]

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

◆ end() [2/2]

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

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

◆ equal()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
bool hxarray< T, capacity_ >::equal ( const hxarray< T, capacity_ > & 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.

◆ find() [1/2]

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

◆ find() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T * hxarray< 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<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
T * hxarray< T, capacity_ >::find_if ( callable_t_ && callable_)

◆ find_if() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
const T * hxarray< T, capacity_ >::find_if ( callable_t_ && callable_) const

Finds the first element for which the predicate returns true.

Returns end() if no element matches.

  • callable : A callable returning boolean.

◆ for_each() [1/2]

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

◆ for_each() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename callable_t_>
void hxarray< T, capacity_ >::for_each ( callable_t_ && callable_) const

Calls a function, lambda, or std::function on each element.

  • callable : A callable.

◆ full()

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

Returns true if the array has been allocated.

◆ hash()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxhash_t hxarray< T, capacity_ >::hash ( void ) const

Returns a hash mixing the hashes of every element in order using hxkey_hash.

◆ insertion_sort()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxarray< T, capacity_ >::insertion_sort ( void )
noexcept

Sorts the array with insertion sort using hxkey_less.

◆ less()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
bool hxarray< T, capacity_ >::less ( const hxarray< T, capacity_ > & x_) const

Returns true if this array compares less than x using hxkey_equal and hxkey_less.

Callers must check the return value to observe the ordering result.

  • x : The other array.

◆ max_size()

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

Returns the capacity of the array.

◆ memcpy()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxarray< T, capacity_ >::memcpy ( const hxarray< T, capacity_ > & x_)

Copies another hxarray using memcpy.

  • x : The other array.

◆ memset()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxarray< 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=() [1/3]

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

Assigns the contents of another hxarray of the same capacity.

◆ operator=() [2/3]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename other_value_t_, hxsize_t array_length_>
void hxarray< 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 };
current_values = initial_values;
  • array : A const array of exactly capacity elements.

◆ operator=() [3/3]

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

Move assigns from a temporary hxarray.

Requires hxallocator_dynamic_capacity.

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
const T & hxarray< 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.

◆ or_else() [1/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
auto hxarray< T, capacity_ >::or_else ( this self_t_ && self_,
const T * it_,
callable_t_ && callable_ )->decltype(self_.end())

Iterator overload of or_else.

  • it : An iterator to an element or end().
  • callable : The function to call for end(). Must return an iterator.

◆ or_else() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename callable_t_>
auto hxarray< T, capacity_ >::or_else ( this self_t_ && self_,
hxsize_t index_,
callable_t_ && callable_ )->decltype(self_.end())

Returns an iterator to the element at index, or the result of calling callable when the index is outside the array.

  • index : The 0-based position of the element.
  • callable : The function to call when lookup fails. Must return a iterator.

◆ reserve()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxarray< T, capacity_ >::reserve ( hxsize_t size_,
hxsystem_allocator_t allocator_ = hxsystem_allocator_current,
hxalignment_t alignment_ = hxalignment )
noexcept

Allocates storage for size elements and default constructs them when capacity is hxallocator_dynamic_capacity.

The current capacity becomes size elements. Reallocation is not allowed. When capacity is fixed, size must equal capacity.

  • size : The number of elements to allocate and construct.
  • allocator : The memory manager ID to use for allocation.
  • alignment : The alignment to use for the allocation.

◆ size()

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

Returns the number of elements in the array.

◆ size_bytes()

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

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

◆ sort()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxarray< T, capacity_ >::sort ( void )
noexcept

Sorts the array using hxkey_less.

◆ swap()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxarray< T, capacity_ >::swap ( hxarray< 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.

◆ value_or() [1/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename... args_t_>
T hxarray< T, capacity_ >::value_or ( this self_t_ && self_,
const T * it_,
args_t_ &&... args_ )

Iterator overload of value_or.

  • it : A const iterator to an element or end().
  • args : The arguments used to construct the value for end().

◆ value_or() [2/2]

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename self_t_, typename... args_t_>
T hxarray< T, capacity_ >::value_or ( this self_t_ && self_,
hxsize_t index_,
args_t_ &&... args_ )

Returns a copy of the element at index, or a T constructed from args when the index is outside the array.

  • index : The 0-based position of the element.
  • args : The arguments used to construct the value when lookup fails.

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