U++ algorithms are designed to work on Ranges. Range is a type that has (at minimum)
Standard begin() / end() methods.
GetCount() that returns the number of elements in Range (can be implemented as end - begin)
operator[] (can be implemented as begin()[i])
Standard Ranges usually also implement ToString and comparisons (if it is possible).
Usually, Range is either U++ container or just some part of it.
U++ provides these Range related typedefs and template functions:
template <class Range> using ValueTypeOf;
Returns the type of elements of Range.
template <class Range> using IteratorOf;
template <class Range> using ConstIteratorOf'
Returns the type of Iterator / ConstIterator of range.
template <class I>
SubRangeClass<I> SubRange(I begin, I end)
Makes a Range based on begin/end iterators.
template <class I>
SubRangeClass<I> SubRange(I begin, int count)
Makes a Range based on begin iterator and count.
template <class C>
auto SubRange(C&& c, int pos, int count);
Makes a Range as subrange of some other Range (e.g. container).
template <C> auto SubRangeFrom(C&& c, int pos)
Same as SubRange(c, pos ,c.GetCount() - pos).
template <class Range> using SubRangeOf;
Returns the type of SubRange of some Range.
template <class T>
ConstRangeClass<T> ConstRange(const T& value, int count)
Creates a Range of count elements equal to value.
template <class T>
ConstRangeClass<T> ConstRange(int count)
Creates a Range of count default constructed elements T.
template <class BaseRange>
ReverseRangeClass<BaseRange> ReverseRange(BaseRange&& r)
Makes a Range reverting the order of elements of r. First element of r becomes the last element of ReverseRange etc..
template <class BaseRange>
ViewRangeClass<BaseRange> ViewRange(BaseRange&& r, Vector<int>&& ndx)
Creates a view of BaseRange r based on mapping ndx. Element at ndx[0] becomes a first element of a new Range, ndx[1] second etc..
template <class BaseRange, class Predicate>
ViewRangeClass<BaseRange> FilterRange(BaseRange&& r, Predicate p)
Same as ViewRangeClass<BaseRange>(r, FindAll(r, p)). Creates a view of elements of master Range that satisfy condition p.
template <class BaseRange, class Predicate>
ViewRangeClass<BaseRange> SortedRange(BaseRange&& r, Predicate p)
Returns a view of range r sorted by predicate p.
template <class BaseRange>
ViewRangeClass<BaseRange> SortedRange(BaseRange&& r)
Returns a view of range r sorted by std::less predicate.
|