Encodes a sequence of integral type T
.
More...
#include <integer_sequence.hpp>
Public Types | |
using | ValueType = T |
using | ThisType = integer_sequence< T, Is... > |
template<T I> | |
using | prepend = integer_sequence< T, I, Is... > |
An integer_sequence<T> with I added to the start. More... | |
template<T I> | |
using | append = integer_sequence< T, Is..., I > |
An integer_sequence<T> with I added to the end. More... | |
template<int... Qs> | |
using | pick = integer_sequence< T, get(Qs)... > |
An integer_sequence<T> composed of the elements from this list given by Qs... . More... | |
template<int Start, int End = Size> | |
using | slice = decltype(sliceHelper< Start >(std::make_integer_sequence< int, End - Start >())) |
A list formed from elements in the range [Start , End ). More... | |
template<typename O > | |
using | cat = decltype(catifier(O{})) |
A list formed by concatenating this list with another one. More... | |
template<int J, T I> | |
using | insert = typename slice< 0, J >::template append< I >::template cat< slice< J > > |
A list formed by adding an element at a given index into this list. More... | |
template<int Index, T NewValue> | |
using | set = typename slice< 0, Index >::template append< NewValue >::template cat< slice< Index+1 > > |
A list equal to this one with one element changed. More... | |
template<int J> | |
using | removeIndex = typename slice< 0, J >::template cat< slice< J+1 > > |
A list formed by removing the element at a given index in this list. More... | |
template<int Start, int End> | |
using | removeRange = typename slice< 0, Start >::template cat< slice< End > > |
Remove a range of values from Start to End - 1 inclusive. More... | |
template<typename OtherList > | |
using | merge = decltype(mergeHelper< OtherList >()) |
Merge a sorted list with this also-sorted-list, as in merge sort. More... | |
template<T I> | |
using | remove = removeIndex< Find< sp::tm::Eq< I > >()> |
Remove the first occurrence of value I . More... | |
template<typename Predicate , typename Defer = Deferred> | |
using | filter = decltype(Defer::template indexFilterHelper< AsIndexPredicate< Predicate >::template S, 0 >()) |
A list containing elements from this one that were chosen using a functor as a filter. More... | |
template<template< int > typename Predicate, typename Defer = Deferred> | |
using | indexFilter = decltype(Defer::template indexFilterHelper< Predicate, 0 >()) |
Filter the list using a predicate that takes index and value, forming a new list. More... | |
template<typename Lambda , typename OutType = T> | |
using | map = integer_sequence< OutType, Lambda{}(Is)... > |
A new list formed by applying a unary functor to every element of this list. More... | |
template<typename TargetType > | |
using | AsType = sp::integer_sequence< TargetType,(TargetType) Is... > |
Convert this to an integer sequence of a different type, relying on whatever conversions are available... More... | |
template<typename Defer = ThisType> | |
using | unique = typename Defer::template indexFilter< UniqueFilter > |
A list formed of the unique elements of this list. More... | |
template<typename Defer = Deferred> | |
using | sortedUnique = decltype(Defer::template sortedUniqueHelper()) |
Get unique elements of a sorted list in linear time. More... | |
template<typename Defer = Deferred> | |
using | sort = decltype(Defer::template sortHelper()) |
A sorted version of this list. More... | |
Static Public Member Functions | |
constexpr static int | binarySearch (T Needle, int Start=0, int End=Size) |
Find the index of the first value that is >= Needle . More... | |
constexpr static std::pair< int, int > | binarySearchRange (T rangeStart, T rangeEnd, int Start=0, int End=Size) |
Find the indices of all values satisfying rangeStart <= X < rangeEnd in logarithmic time. (must be sorted). More... | |
constexpr static T | get (int i) |
Get an element from the list. More... | |
constexpr static T | last () |
Get the last element from the list. More... | |
template<typename Predicate > | |
static constexpr int | Find (int FromIndex=0) |
Return the index of the first element for which Predicate<I>::value is true, starting from index I , or -1 if there is no such element. More... | |
template<typename Predicate > | |
static constexpr int | Find (Predicate lambda, int FromIndex=0) |
Return the index of the first element for which lambda(value) is true, starting from index I , or -1 if there is no such element. More... | |
static constexpr int | indexOf (T x, int fromIndex=0) |
Find the index of the first occurence of x after index fromIndex , or -1 if it doesn't exist. More... | |
template<T... Xs> | |
static constexpr int | indexOf (integer_sequence< T, Xs... > seq, int fromIndex=0) |
Find the index of the first time a given integer sequence occurs as a subsequence of this one. More... | |
template<T... Ts> | |
constexpr static bool | StartsWith () |
Determine if this list starts with the given sequence of values. More... | |
constexpr static bool | contains (T I) |
Returns true iff the given element is in the list. More... | |
Static Public Attributes | |
constexpr static int | Size = sizeof...(Is) |
constexpr static bool | Empty = Size == 0 |
constexpr static std::array< T, Size > | Values {Is...} |
template<typename OtherSeq > | |
constexpr static bool | equals = std::is_same_v<ThisType, OtherSeq> |
Compare lists for equality. More... | |
template<typename Predicate > | |
static constexpr bool | All = (Predicate{}(Is) && ...) |
True iff the given functor predicate matches all elements of the list. More... | |
template<typename Predicate > | |
static constexpr bool | Any = (Predicate{}(Is) || ...) |
True iff the given functor predicate matches any element of the list. More... | |
Encodes a sequence of integral type T
.
Conceptually similar to std::integer_sequence
, but with a rich API that provides high-level list manipulations such as filtering, slicing, sorting, appending, etc.
T | The type of elements in the sequence. |
Is | The elements of the list. |
using sp::integer_sequence< T, Is >::append = integer_sequence<T, Is..., I> |
An integer_sequence<T>
with I
added to the end.
I | The value to append to this list. |
using sp::integer_sequence< T, Is >::AsType = sp::integer_sequence<TargetType, (TargetType) Is...> |
Convert this to an integer sequence of a different type, relying on whatever conversions are available...
using sp::integer_sequence< T, Is >::cat = decltype(catifier(O{})) |
A list formed by concatenating this list with another one.
This list appears first, followed by the contents of the other one.
O | The other list to join with this one. |
using sp::integer_sequence< T, Is >::filter = decltype(Defer::template indexFilterHelper<AsIndexPredicate<Predicate>::template S, 0>()) |
A list containing elements from this one that were chosen using a functor as a filter.
Predicate | The predicate functor to use. |
using sp::integer_sequence< T, Is >::indexFilter = decltype(Defer::template indexFilterHelper<Predicate, 0>()) |
Filter the list using a predicate that takes index and value, forming a new list.
using sp::integer_sequence< T, Is >::insert = typename slice<0, J>::template append<I>::template cat<slice<J> > |
A list formed by adding an element at a given index into this list.
J | The target index. The new element is inserted at this position and all other elements shift to the right by one position. This index may be one beyond the end of this list, in which case the element is appended to the list. If it is otherwise out of bounds, the program refuses to compile. |
I | The new element. |
using sp::integer_sequence< T, Is >::map = integer_sequence<OutType, Lambda{}(Is)...> |
A new list formed by applying a unary functor to every element of this list.
Lambda | A unary functor. |
using sp::integer_sequence< T, Is >::merge = decltype(mergeHelper<OtherList>()) |
Merge a sorted list with this also-sorted-list, as in merge sort.
using sp::integer_sequence< T, Is >::pick = integer_sequence<T, get(Qs)...> |
An integer_sequence<T>
composed of the elements from this list given by Qs...
.
If you want to use another integer_sequence
to provide Qs...
, you will have to use pattern matching to extract the template parameter.
Qs | A parameter pack listing elements to take from this list. |
using sp::integer_sequence< T, Is >::prepend = integer_sequence<T, I, Is...> |
An integer_sequence<T>
with I
added to the start.
I | The value to prepend to this list. |
using sp::integer_sequence< T, Is >::remove = removeIndex<Find<sp::tm::Eq<I> >()> |
Remove the first occurrence of value I
.
The value must be present in the list, otherwise the program will refuse to compile.
I | The value to remove. |
using sp::integer_sequence< T, Is >::removeIndex = typename slice<0, J>::template cat<slice<J + 1> > |
A list formed by removing the element at a given index in this list.
J | The index of the element to remove. |
using sp::integer_sequence< T, Is >::removeRange = typename slice<0, Start>::template cat<slice<End> > |
Remove a range of values from Start
to End - 1
inclusive.
using sp::integer_sequence< T, Is >::set = typename slice<0, Index>::template append<NewValue>::template cat<slice<Index + 1> > |
A list equal to this one with one element changed.
Index | The element to change. If out-of-bounds, the program will not compile |
NewValue | The new value to store. |
using sp::integer_sequence< T, Is >::slice = decltype(sliceHelper<Start>(std::make_integer_sequence<int, End - Start>())) |
A list formed from elements in the range [Start
, End
).
Start | The index of the element to include in the output list. |
End | The index of the element to exclude from the output list. |
using sp::integer_sequence< T, Is >::sort = decltype(Defer::template sortHelper()) |
A sorted version of this list.
O(n²)
. It may cause very long compile times if used too much.using sp::integer_sequence< T, Is >::sortedUnique = decltype(Defer::template sortedUniqueHelper()) |
Get unique elements of a sorted list in linear time.
This is exactly like unique
, except:
Note that calling sort<> and then using this function is more expensive than using unique
.
using sp::integer_sequence< T, Is >::unique = typename Defer::template indexFilter<UniqueFilter> |
A list formed of the unique elements of this list.
The first occurrence of each element is retained, and their relative ordering preserved. The input list does not have to be sorted.
O(n²)
. It may cause very long compile times if used too much.
|
staticconstexpr |
Find the index of the first value that is >= Needle
.
|
staticconstexpr |
Find the indices of all values satisfying rangeStart <= X < rangeEnd
in logarithmic time. (must be sorted).
|
staticconstexpr |
Returns true iff the given element is in the list.
I | The element to look for. Check if an element is in the list |
|
staticconstexpr |
Return the index of the first element for which Predicate<I>::value is true, starting from index I
, or -1
if there is no such element.
Predicate | The functor to use. |
|
staticconstexpr |
Return the index of the first element for which lambda(value)
is true, starting from index I
, or -1
if there is no such element.
This version is more efficient than the functor-based one.
lambda | A lambda that accepts one T and returns a bool. |
FromIndex | The first index to start searching from. |
|
staticconstexpr |
Get an element from the list.
|
staticconstexpr |
Find the index of the first time a given integer sequence occurs as a subsequence of this one.
This is particularly useful for finding substrings when using integer_sequence<char>
as a compile-time string.
seq | An integer_sequence of the same type. |
fromIndex | The first index to start searching from. |
|
staticconstexpr |
Find the index of the first occurence of x
after index fromIndex
, or -1 if it doesn't exist.
x | A lambda that accepts one T and returns a bool. |
fromIndex | The first index to start searching from. |
|
staticconstexpr |
Get the last element from the list.
|
staticconstexpr |
Determine if this list starts with the given sequence of values.
This is more efficient than using the multi-elemeent indexOf()
function, where this is applicable.
Ts | The elements to look for. |
|
staticconstexpr |
True iff the given functor predicate matches all elements of the list.
Predicate | The functor predicate to use. |
|
staticconstexpr |
True iff the given functor predicate matches any element of the list.
Predicate | The functor predicate to use. |
|
staticconstexpr |
Compare lists for equality.
Constant-time.
OtherSeq | The sequence to compare to. |