libhatchet
Loading...
Searching...
No Matches
hxrange.hpp File Reference

Go to the source code of this file.

Classes

class  hxrange< iterator_t_ >

Functions

template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
HX_NS_BEGIN_ constexpr auto hxlower_bound (range_t_ &&range_, const value_t_ &value_, const less_t_ &less_) -> decltype(range_.begin())
template<typename iterator_t_>
constexpr hxrange< iterator_t_ > hxmake_range (iterator_t_ begin_, iterator_t_ end_)
template<typename T, size_t N_>
constexpr hxrange< T * > hxmake_range (T(&array_)[N_])
template<hxrange_concept_ range_t_, typename callable_t_>
constexpr bool hxall_of (range_t_ &&range_, callable_t_ &&callable_)
template<hxrange_concept_ range_t_, typename callable_t_>
constexpr bool hxany_of (range_t_ &&range_, callable_t_ &&callable_)
template<hxrandom_iterator_concept_ iterator_t_, typename value_t_, typename less_t_>
constexpr iterator_t_ hxbinary_search (iterator_t_ begin_, iterator_t_ end_, const value_t_ &value_, const less_t_ &less_)
template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
constexpr auto hxbinary_search (range_t_ &&range_, const value_t_ &value_, const less_t_ &less_) -> decltype(range_.begin())
template<hxsorted_range_concept_ range_t_, typename value_t_>
constexpr auto hxbinary_search (range_t_ &&range_, const value_t_ &value_) -> decltype(range_.begin())
template<hxrange_concept_ range_t_, typename callable_t_>
constexpr hxsize_t hxcount_if (range_t_ &&range_, callable_t_ &&callable_)
template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_, typename equal_t_>
constexpr bool hxequal_range (range0_t_ &&range0_, range1_t_ &&range1_, const equal_t_ &equal_)
template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_>
constexpr bool hxequal_range (range0_t_ &&range0_, range1_t_ &&range1_)
template<typename T, typename... args_t_>
constexpr T hxexchange (T &obj_, args_t_ &&... args_) noexcept
template<hxrange_concept_ range_t_, typename callable_t_>
constexpr auto hxfind_if (range_t_ &&range_, callable_t_ &&callable_) -> decltype(range_.begin())
template<hxrange_concept_ range_t_, typename callable_t_>
constexpr callable_t_ hxfor_each (range_t_ &&range_, callable_t_ &&callable_)
template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_, typename equal_t_, typename less_t_>
constexpr bool hxless_range (range0_t_ &&range0_, range1_t_ &&range1_, const equal_t_ &equal_, const less_t_ &less_)
template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_>
constexpr bool hxless_range (range0_t_ &&range0_, range1_t_ &&range1_)
template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
constexpr auto hxlower_bound (range_t_ &&range_, const value_t_ &value_, const less_t_ &less_) -> decltype(range_.begin())
template<hxrandom_range_concept_ range_t_, typename value_t_>
constexpr auto hxlower_bound (range_t_ &&range_, const value_t_ &value_) -> decltype(range_.begin())
template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
constexpr auto hxupper_bound (range_t_ &&range_, const value_t_ &value_, const less_t_ &less_) -> decltype(range_.begin())
template<hxrandom_range_concept_ range_t_, typename value_t_>
constexpr auto hxupper_bound (range_t_ &&range_, const value_t_ &value_) -> decltype(range_.begin())

Detailed Description

Read-only range utilities for libhatchet.

Includes support for callables when defining custom key operations. Otherwise T::operator<(const T&) and T::operator==(const T&) are used. The other relational operators are not used.

See hxset_algorithms.hpp for iterator based set algorithms. See hxsort.hpp for sorting algorithms including hxinsertion_sort, hxheapsort and hxsort.

All the hxrestrict_t sprinkled around has measurable benefits in certain cases. Clang is better at utilizing that hint.

Function Documentation

◆ hxall_of()

template<hxrange_concept_ range_t_, typename callable_t_>
bool hxall_of ( range_t_ && range_,
callable_t_ && callable_ )
inlineconstexpr

hxall_of - Returns true if the predicate callable returns true for every element of range.

Returns true for an empty range. Requires a forward-iterator.

◆ hxany_of()

template<hxrange_concept_ range_t_, typename callable_t_>
bool hxany_of ( range_t_ && range_,
callable_t_ && callable_ )
inlineconstexpr

hxany_of - Returns true if the predicate callable returns true for at least one element of range.

Returns false for an empty range. Requires a forward-iterator.

◆ hxbinary_search() [1/3]

template<hxrandom_iterator_concept_ iterator_t_, typename value_t_, typename less_t_>
iterator_t_ hxbinary_search ( iterator_t_ begin_,
iterator_t_ end_,
const value_t_ & value_,
const less_t_ & less_ )
inlineconstexpr

hxbinary_search - Performs a binary search for value in the sorted range [begin, end).

Returns end if the value is not found. Unsorted data will lead to errors. The first of non-unique values is returned. The less callable returns true if the first argument is ordered before (i.e., is less than) the second. Requires a random-iterator.

◆ hxbinary_search() [2/3]

template<hxsorted_range_concept_ range_t_, typename value_t_>
auto hxbinary_search ( range_t_ && range_,
const value_t_ & value_ )->decltype(range_.begin())
inlineconstexpr

hxbinary_search (specialization) - An overload of hxbinary_search that searches for value in the sorted range using hxkey_less.

Requires a sorted-iterator.

◆ hxbinary_search() [3/3]

template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
auto hxbinary_search ( range_t_ && range_,
const value_t_ & value_,
const less_t_ & less_ )->decltype(range_.begin())
inlineconstexpr

hxbinary_search - An overload of hxbinary_search over range.

Requires a random-iterator.

◆ hxcount_if()

template<hxrange_concept_ range_t_, typename callable_t_>
hxsize_t hxcount_if ( range_t_ && range_,
callable_t_ && callable_ )
inlineconstexpr

hxcount_if - Returns the number of elements of range for which the predicate callable returns true.

Requires a forward-iterator.

◆ hxequal_range() [1/2]

template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_>
bool hxequal_range ( range0_t_ && range0_,
range1_t_ && range1_ )
inlineconstexpr

hxequal_range (specialization) - An overload of hxequal_range that uses hxkey_equal over range0 and range1.

Requires a forward-iterator.

◆ hxequal_range() [2/2]

template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_, typename equal_t_>
bool hxequal_range ( range0_t_ && range0_,
range1_t_ && range1_,
const equal_t_ & equal_ )
inlineconstexpr

hxequal_range - Returns true if range0 and range1 have the same length and equal returns true for every pair of elements at corresponding positions.

Requires a forward-iterator.

◆ hxexchange()

template<typename T, typename... args_t_>
T hxexchange ( T & obj_,
args_t_ &&... args_ )
inlineconstexprnoexcept

hxexchange - Replaces obj with a T constructed from args and returns the old value of obj.

T must be move-constructible. Useful in constructor initialization lists.

◆ hxfind_if()

template<hxrange_concept_ range_t_, typename callable_t_>
auto hxfind_if ( range_t_ && range_,
callable_t_ && callable_ )->decltype(range_.begin())
inlineconstexpr

hxfind_if - Returns an iterator to the first element of range for which the predicate callable returns true.

Returns range.end() if no element matches. Requires a forward-iterator.

◆ hxfor_each()

template<hxrange_concept_ range_t_, typename callable_t_>
callable_t_ hxfor_each ( range_t_ && range_,
callable_t_ && callable_ )
inlineconstexpr

hxfor_each - Applies the callable to each element of range in order.

Returns the callable after it has been applied to every element. Requires a forward-iterator.

◆ hxless_range() [1/2]

template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_>
bool hxless_range ( range0_t_ && range0_,
range1_t_ && range1_ )
inlineconstexpr

hxless_range (specialization) - An overload of hxless_range that uses hxkey_equal and hxkey_less over range0 and range1.

Requires a forward-iterator.

◆ hxless_range() [2/2]

template<hxrange_concept_ range0_t_, hxrange_concept_ range1_t_, typename equal_t_, typename less_t_>
bool hxless_range ( range0_t_ && range0_,
range1_t_ && range1_,
const equal_t_ & equal_,
const less_t_ & less_ )
inlineconstexpr

hxless_range - Returns true if range0 is lexicographically less than range1, using equal to detect matching elements and less to order the first pair that differs.

A range that is a proper prefix of the other is less than the other. Costs one equal call and, at the deciding position only, one less call per element. Requires a forward-iterator.

◆ hxlower_bound() [1/3]

template<hxrandom_range_concept_ range_t_, typename value_t_>
auto hxlower_bound ( range_t_ && range_,
const value_t_ & value_ )->decltype(range_.begin())
inlineconstexpr

hxlower_bound (specialization) - An overload of hxlower_bound over range that uses hxkey_less.

Requires a random-iterator.

◆ hxlower_bound() [2/3]

template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
auto hxlower_bound ( range_t_ && range_,
const value_t_ & value_,
const less_t_ & less_ )->decltype(range_.begin())
inlineconstexpr

hxlower_bound - Returns the first position in the sorted range where value could be inserted without violating the ordering.

Returns range.end() if no element is ordered after or equivalent to value. Unsorted data will lead to errors. The less callable returns true if the first argument is ordered before (i.e., is less than) the second. Requires a random-iterator.

◆ hxlower_bound() [3/3]

template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
HX_NS_BEGIN_ constexpr auto hxlower_bound ( range_t_ && range_,
const value_t_ & value_,
const less_t_ & less_ )->decltype(range_.begin())
inlineconstexpr

hxlower_bound - Returns the first position in the sorted range where value could be inserted without violating the ordering.

Returns range.end() if no element is ordered after or equivalent to value. Unsorted data will lead to errors. The less callable returns true if the first argument is ordered before (i.e., is less than) the second. Requires a random-iterator.

◆ hxmake_range() [1/2]

template<typename iterator_t_>
hxrange< iterator_t_ > hxmake_range ( iterator_t_ begin_,
iterator_t_ end_ )
inlineconstexpr

hxmake_range - Returns an hxrange deduced from the iterator pair [begin, end).

  • begin : Iterator to the first element.
  • end : Iterator one past the last element.

◆ hxmake_range() [2/2]

template<typename T, size_t N_>
hxrange< T * > hxmake_range ( T(&) array_[N_])
inlineconstexpr

◆ hxupper_bound() [1/2]

template<hxrandom_range_concept_ range_t_, typename value_t_>
auto hxupper_bound ( range_t_ && range_,
const value_t_ & value_ )->decltype(range_.begin())
inlineconstexpr

hxupper_bound (specialization) - An overload of hxupper_bound over range that uses hxkey_less.

Requires a random-iterator.

◆ hxupper_bound() [2/2]

template<hxrandom_range_concept_ range_t_, typename value_t_, typename less_t_>
auto hxupper_bound ( range_t_ && range_,
const value_t_ & value_,
const less_t_ & less_ )->decltype(range_.begin())
inlineconstexpr

hxupper_bound - Returns the first position in the sorted range whose element is ordered after value.

Returns range.end() if no such element exists. Unsorted data will lead to errors. The less callable returns true if the first argument is ordered before (i.e., is less than) the second. Requires a random-iterator.