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_type = 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
 ~hxarray (void) noexcept
void operator= (const 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_)
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 * 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 equal (const hxarray &x_) const
const T * end (void) const
T * end (void)
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 * get (hxsize_t index_) const
T * get (hxsize_t index_)
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)
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

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 and hxkey_equal overloads. They default to using operators < and ==. See hxalgorithm.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_type

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

value_type - Publishes the value type.

Doesn't end with _t because of the standard.

Constructor & Destructor Documentation

◆ hxarray() [1/6]

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

Default constructs all elements.

◆ hxarray() [2/6]

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/6]

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/6]

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/6]

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.

e.g.,

static const int initial_values[4] = { 5, 4, 3, 2 };
hxarray<int, 4u> current_values(initial_values);
hxarray - Implements std::array with a few things added.
Definition hxarray.hpp:54
  • array : A const array. The array length must equal capacity or capacity must be dynamic.

◆ hxarray() [6/6]

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()

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_)

A non-const version of all_of.

◆ 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:180
  • callable : A callable returning boolean. !all_of(x) -> any_not(x).

◆ 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_)

A non-const version of any_of.

◆ 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).

◆ assign()

template<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename iter_t_>
void hxarray< 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<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename range_t_>
requires (!hxis_lvalue_reference<range_t_>::value)
void hxarray< 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<hxarray_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename range_t_>
void hxarray< 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. Use operator= to assign from a C-style array.

  • range : The range to copy elements from.

◆ begin() [1/2]

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

Returns a T* to the beginning of the array.

◆ 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_)

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<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.

◆ end() [1/2]

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

Returns a T* to the end of the array.

◆ 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_)

Non-const version of find using hxkey_equal.

  • value : The value to locate.

◆ 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_)

Non-const version of find_if.

◆ 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_)

Non-const version of for_each.

◆ 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.

◆ get() [1/2]

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

◆ 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/2]

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/2]

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.

The array length must equal the capacity of this array.

  • array : A const array of array_length value_t.

◆ operator[]() [1/2]

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

◆ 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.


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