header_utils
Loading...
Searching...
No Matches
Ranges

Ranges and such. More...

template<typename RANGE >
using ghassanpl::range_value = std::ranges::range_value_t< std::decay_t< RANGE > >
 Helper template to get the value type of a type that decays to a range
 
template<typename RANGE >
using ghassanpl::range_iterator = std::ranges::iterator_t< std::decay_t< RANGE > >
 Helper template to get the iterator type of a type that decays to a range
 
constexpr __contains_fn ghassanpl::contains
 contains(range, el)
 
constexpr __contains_subrange_fn ghassanpl::contains_subrange
 contains_subrange(range, subrange)
 
constexpr bool ghassanpl::valid_index (random_access_range auto &range, std::integral auto index)
 Returns whether or not a given integer is a valid index to a random access range
 
constexpr auto ghassanpl::modulo_index (size_t range_size, std::integral auto index)
 Returns index converted to a valid index into a range of range_size as if using modulo arithmetic.
 
constexpr auto ghassanpl::modulo_index (random_access_range auto &range, std::integral auto index)
 Returns an valid index into range, created from index as if range is circular.
 
constexpr decltype(autoghassanpl::at (random_access_range auto &range, std::integral auto index)
 Returns a reference to the value at index of range
 
constexpr auto ghassanpl::at_ptr (random_access_range auto &range, std::integral auto index) -> decltype(std::to_address(std::ranges::begin(range)+index))
 Returns a pointer to the value at index of range if index is valid, else returns null.
 
constexpr decltype(autoghassanpl::modulo_at (random_access_range auto &range, std::integral auto index)
 Returns a reference to the value at modulo_index of range
 
template<random_access_range RANGE, typename T >
requires requires (T value, RANGE range) { { *std::ranges::begin(range) == value } -> std::convertible_to<bool>; }
constexpr auto ghassanpl::index_of (RANGE const &range, T &&value) -> std::iter_difference_t< range_iterator< RANGE > >
 Find a value in range and returns an index to it.
 
template<random_access_range RANGE, typename T = range_value<RANGE>>
constexpr auto ghassanpl::at_or_default (RANGE &&range, std::integral auto index, T &&default_value)
 Return the element at index or default_value if not a valid index.
 
template<random_access_range RANGE, typename FUNC >
requires range_predicate<RANGE, FUNC>
constexpr auto ghassanpl::find_index (RANGE const &range, FUNC &&func) -> std::iter_difference_t< range_iterator< RANGE > >
 Find a value in range and returns an index to it.
 
template<std::ranges::range RANGE, typename FUNC >
requires range_predicate<RANGE, FUNC>
constexpr auto ghassanpl::find_ptr (RANGE &range, FUNC &&func)
 Find a value in range and returns a pointer to it, or null if none found.
 
template<random_access_range RANGE, typename FUNC , typename DEF_TYPE = range_value<RANGE>>
requires range_predicate<RANGE, FUNC>
auto ghassanpl::find_if_or_default (RANGE &range, FUNC &&func, DEF_TYPE &&default_value=DEF_TYPE{})
 
constexpr auto ghassanpl::to_index (random_access_iterator auto iterator, random_access_range auto const &range)
 Turns an iterator to range to an index.
 
template<contiguous_range RANGE>
constexpr bool ghassanpl::valid_address (RANGE &&range, range_value< RANGE > *pointer)
 Returns whether or not pointer is a valid pointer to an element in the contiguous range
 
template<typename T , size_t N = std::dynamic_extent>
constexpr std::pair< std::span< T >, std::span< T > > ghassanpl::split_at (std::span< T, N > span, size_t index)
 Span stuff.
 
template<typename T , size_t N = std::dynamic_extent>
constexpr std::array< std::span< T >, 3 > ghassanpl::split_at (std::span< T, N > span, size_t index, size_t size)
 
template<typename T , size_t N = std::dynamic_extent>
constexpr std::pair< T *, T * > ghassanpl::as_range (std::span< T, N > span)
 
template<typename TO , typename FROM , size_t N = std::dynamic_extent>
auto ghassanpl::span_cast (std::span< FROM, N > bytes) noexcept
 Casts a span of objects of type FROM to a span of objects of type TO Does not perform any checks, specifically, no alignment or size checks are performed.
 
template<typename T1 , size_t N1, typename T2 , size_t N2>
constexpr bool ghassanpl::are_adjacent (std::span< T1, N1 > s1, std::span< T2, N2 > s2)
 
template<typename T1 , size_t N1, typename T2 , size_t N2>
constexpr bool ghassanpl::are_overlapping (std::span< T1, N1 > s1, std::span< T2, N2 > s2)
 
template<typename T , size_t N1, typename U , size_t N2>
requires std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<U>>
constexpr bool ghassanpl::ends_with (std::span< T, N1 > s1, std::span< U, N2 > s2)
 
template<typename T , size_t N1, typename U , size_t N2>
requires std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<U>>
constexpr bool ghassanpl::starts_with (std::span< T, N1 > s1, std::span< U, N2 > s2)
 
template<typename T , std::size_t... Ns>
constexpr auto ghassanpl::join (std::array< T, Ns >... arrays)
 Arrays.
 
template<typename T , size_t LL, typename... ARGS>
requires (std::same_as<std::remove_cvref_t<ARGS>, T> && ...)
constexpr auto ghassanpl::join (std::array< T, LL > rhs, ARGS &&... args)
 
template<class CONTAINER , std::ranges::input_range RANGE, class... TYPES>
requires (!std::ranges::view<CONTAINER>)
constexpr CONTAINER ghassanpl::to (RANGE &&range, TYPES &&... args)
 to<container>();
 
template<template< class... > class CONTAINER, std::ranges::input_range RANGE, class... TYPES, class _Deduced = std::remove_pointer_t<decltype(detail::to_helper<CONTAINER, RANGE, TYPES...>())>>
constexpr _Deduced ghassanpl::to (RANGE &&_Range, TYPES &&... ARGS)
 to<container>();
 

Detailed Description

Ranges and such.

Typedef Documentation

◆ range_iterator

template<typename RANGE >
using ghassanpl::range_iterator = typedef std::ranges::iterator_t<std::decay_t<RANGE> >

Helper template to get the iterator type of a type that decays to a range

Definition at line 30 of file ranges.h.

◆ range_value

template<typename RANGE >
using ghassanpl::range_value = typedef std::ranges::range_value_t<std::decay_t<RANGE> >

Helper template to get the value type of a type that decays to a range

Definition at line 26 of file ranges.h.

Function Documentation

◆ are_adjacent()

template<typename T1 , size_t N1, typename T2 , size_t N2>
constexpr bool ghassanpl::are_adjacent ( std::span< T1, N1 s1,
std::span< T2, N2 s2 
)
constexpr

Definition at line 178 of file ranges.h.

◆ are_overlapping()

template<typename T1 , size_t N1, typename T2 , size_t N2>
constexpr bool ghassanpl::are_overlapping ( std::span< T1, N1 s1,
std::span< T2, N2 s2 
)
constexpr

Definition at line 185 of file ranges.h.

◆ as_range()

template<typename T , size_t N = std::dynamic_extent>
constexpr std::pair< T *, T * > ghassanpl::as_range ( std::span< T, N span)
constexpr

Definition at line 164 of file ranges.h.

◆ at()

constexpr decltype(auto) ghassanpl::at ( random_access_range auto range,
std::integral auto  index 
)
constexpr

Returns a reference to the value at index of range

Definition at line 59 of file ranges.h.

◆ at_or_default()

template<random_access_range RANGE, typename T = range_value<RANGE>>
constexpr auto ghassanpl::at_or_default ( RANGE &&  range,
std::integral auto  index,
T &&  default_value 
)
constexpr

Return the element at index or default_value if not a valid index.

Definition at line 95 of file ranges.h.

◆ at_ptr()

constexpr auto ghassanpl::at_ptr ( random_access_range auto range,
std::integral auto  index 
) -> decltype(std::to_address(std::ranges::begin(range) + index))
constexpr

Returns a pointer to the value at index of range if index is valid, else returns null.

Definition at line 67 of file ranges.h.

◆ ends_with()

template<typename T , size_t N1, typename U , size_t N2>
requires std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<U>>
constexpr bool ghassanpl::ends_with ( std::span< T, N1 s1,
std::span< U, N2 s2 
)
constexpr

Definition at line 192 of file ranges.h.

◆ find_if_or_default()

template<random_access_range RANGE, typename FUNC , typename DEF_TYPE = range_value<RANGE>>
requires range_predicate<RANGE, FUNC>
auto ghassanpl::find_if_or_default ( RANGE range,
FUNC &&  func,
DEF_TYPE &&  default_value = DEF_TYPE{} 
)

Definition at line 123 of file ranges.h.

◆ find_index()

template<random_access_range RANGE, typename FUNC >
requires range_predicate<RANGE, FUNC>
constexpr auto ghassanpl::find_index ( RANGE const range,
FUNC &&  func 
) -> std::iter_difference_t<range_iterator<RANGE>>
constexpr

Find a value in range and returns an index to it.

Definition at line 104 of file ranges.h.

◆ find_ptr()

template<std::ranges::range RANGE, typename FUNC >
requires range_predicate<RANGE, FUNC>
constexpr auto ghassanpl::find_ptr ( RANGE range,
FUNC &&  func 
)
constexpr

Find a value in range and returns a pointer to it, or null if none found.

Definition at line 115 of file ranges.h.

◆ index_of()

template<random_access_range RANGE, typename T >
requires requires (T value, RANGE range) { { *std::ranges::begin(range) == value } -> std::convertible_to<bool>; }
constexpr auto ghassanpl::index_of ( RANGE const range,
T &&  value 
) -> std::iter_difference_t<range_iterator<RANGE>>
constexpr

Find a value in range and returns an index to it.

Definition at line 84 of file ranges.h.

◆ join() [1/2]

template<typename T , size_t LL, typename... ARGS>
requires (std::same_as<std::remove_cvref_t<ARGS>, T> && ...)
constexpr auto ghassanpl::join ( std::array< T, LL rhs,
ARGS &&...  args 
)
constexpr

Definition at line 219 of file ranges.h.

◆ join() [2/2]

template<typename T , std::size_t... Ns>
constexpr auto ghassanpl::join ( std::array< T, Ns >...  arrays)
constexpr

Arrays.

Definition at line 209 of file ranges.h.

◆ modulo_at()

constexpr decltype(auto) ghassanpl::modulo_at ( random_access_range auto range,
std::integral auto  index 
)
constexpr

Returns a reference to the value at modulo_index of range

Precondition
range must not be empty

Definition at line 77 of file ranges.h.

◆ modulo_index() [1/2]

constexpr auto ghassanpl::modulo_index ( random_access_range auto range,
std::integral auto  index 
)
constexpr

Returns an valid index into range, created from index as if range is circular.

Precondition
range must not be empty

Definition at line 52 of file ranges.h.

◆ modulo_index() [2/2]

constexpr auto ghassanpl::modulo_index ( size_t  range_size,
std::integral auto  index 
)
constexpr

Returns index converted to a valid index into a range of range_size as if using modulo arithmetic.

Precondition
range_size > 0

Definition at line 44 of file ranges.h.

◆ span_cast()

template<typename TO , typename FROM , size_t N = std::dynamic_extent>
auto ghassanpl::span_cast ( std::span< FROM, N bytes)
noexcept

Casts a span of objects of type FROM to a span of objects of type TO Does not perform any checks, specifically, no alignment or size checks are performed.

Definition at line 172 of file ranges.h.

◆ split_at() [1/2]

template<typename T , size_t N = std::dynamic_extent>
constexpr std::pair< std::span< T >, std::span< T > > ghassanpl::split_at ( std::span< T, N span,
size_t  index 
)
constexpr

Span stuff.

Definition at line 148 of file ranges.h.

◆ split_at() [2/2]

template<typename T , size_t N = std::dynamic_extent>
constexpr std::array< std::span< T >, 3 > ghassanpl::split_at ( std::span< T, N span,
size_t  index,
size_t  size 
)
constexpr

Definition at line 156 of file ranges.h.

◆ starts_with()

template<typename T , size_t N1, typename U , size_t N2>
requires std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<U>>
constexpr bool ghassanpl::starts_with ( std::span< T, N1 s1,
std::span< U, N2 s2 
)
constexpr

Definition at line 200 of file ranges.h.

◆ to() [1/2]

template<template< class... > class CONTAINER, std::ranges::input_range RANGE, class... TYPES, class _Deduced = std::remove_pointer_t<decltype(detail::to_helper<CONTAINER, RANGE, TYPES...>())>>
constexpr _Deduced ghassanpl::to ( RANGE &&  _Range,
TYPES &&...  ARGS 
)
constexpr

to<container>();

Definition at line 400 of file ranges.h.

◆ to() [2/2]

template<class CONTAINER , std::ranges::input_range RANGE, class... TYPES>
requires (!std::ranges::view<CONTAINER>)
constexpr CONTAINER ghassanpl::to ( RANGE &&  range,
TYPES &&...  args 
)
constexpr

to<container>();

Definition at line 369 of file ranges.h.

◆ to_index()

constexpr auto ghassanpl::to_index ( random_access_iterator auto  iterator,
random_access_range auto const range 
)
constexpr

Turns an iterator to range to an index.

Definition at line 132 of file ranges.h.

◆ valid_address()

template<contiguous_range RANGE>
constexpr bool ghassanpl::valid_address ( RANGE &&  range,
range_value< RANGE > *  pointer 
)
constexpr

Returns whether or not pointer is a valid pointer to an element in the contiguous range

Definition at line 139 of file ranges.h.

◆ valid_index()

constexpr bool ghassanpl::valid_index ( random_access_range auto range,
std::integral auto  index 
)
constexpr

Returns whether or not a given integer is a valid index to a random access range

Definition at line 37 of file ranges.h.

Variable Documentation

◆ contains

constexpr __contains_fn ghassanpl::contains
inlineconstexpr

contains(range, el)

Definition at line 247 of file ranges.h.

◆ contains_subrange

constexpr __contains_subrange_fn ghassanpl::contains_subrange
inlineconstexpr

contains_subrange(range, subrange)

Definition at line 269 of file ranges.h.