Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS > Class Template Reference

A DiscreteRange is a Range where the underlying endpoints are integral (discrete, not continuous); this implies you can iterate over the members of the range, and its endpoints are closed. More...

#include <DiscreteRange.h>

Inheritance diagram for Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >:
Stroika::Foundation::Traversal::Range< T, TRAITS >

Public Member Functions

constexpr DiscreteRange ()=default
 
constexpr Range< T, TRAITS > Intersection (const Range< T, TRAITS > &rhs) const
 
constexpr Range< T, TRAITS > UnionBounds (const Range< T, TRAITS > &rhs) const
 
constexpr UnsignedDifferenceType GetNumberOfContainedPoints () const
 
constexpr DiscreteRange Offset (SignedDifferenceType o) const
 
nonvirtual Iterable< T > Elements () const
 
nonvirtual operator Iterable< T > () const
 
nonvirtual Iterator< T > begin () const
 
- Public Member Functions inherited from Stroika::Foundation::Traversal::Range< T, TRAITS >
constexpr Range ()
 
constexpr Range ReplaceStart (Common::ArgByValueType< T > start) const
 Construct a new Range from this, but with the given start.
 
constexpr Range ReplaceEnd (Common::ArgByValueType< T > end) const
 Construct a new Range from this, but with the given end.
 
constexpr bool empty () const
 
constexpr operator bool () const
 equivalent to not this->empty ();
 
constexpr UnsignedDifferenceType GetDistanceSpanned () const
 
constexpr T GetMidpoint () const
 
constexpr T Pin (T v) const
 
constexpr bool Contains (Common::ArgByValueType< T > r) const
 
nonvirtual constexpr Range Closure () const
 
constexpr bool operator== (const Range &rhs) const
 
constexpr optional< bool > DefinitelyLessThan (const Range &rhs) const
 Compute a less-like notion for Range.
 
template<typename T2 , typename TRAITS2 >
constexpr bool Intersects (const Range< T2, TRAITS2 > &rhs) const
 
constexpr Range Intersection (const Range &rhs) const
 
nonvirtual DisjointRange< T, RangeUnion (const Range &rhs) const
 
constexpr Range UnionBounds (const Range &rhs) const
 
constexpr Range Extend (Common::ArgByValueType< T > value) const
 
constexpr T GetLowerBound () const
 
constexpr T GetUpperBound () const
 
constexpr Range Offset (SignedDifferenceType o) const
 
constexpr Range Times (T o) const
 
nonvirtual Characters::String ToString (const function< Characters::String(const T &)> &elt2String=[](const T &x) -> Characters::String { return Characters::ToString(x);}) const
 

Static Public Member Functions

static constexpr DiscreteRange FullRange ()
 
- Static Public Member Functions inherited from Stroika::Foundation::Traversal::Range< T, TRAITS >
static constexpr Range Ball (Common::ArgByValueType< T > center, Common::ArgByValueType< UnsignedDifferenceType > radius, Openness lhsOpen=TRAITS::kLowerBoundOpenness, Openness rhsOpen=TRAITS::kUpperBoundOpenness)
 returns a range centered around center, with the given radius (and optionally argument openness).
 
static constexpr Range ContainedRange (Common::ArgByValueType< T > begin, Common::ArgByValueType< T > end)
 
static constexpr Range FullRange ()
 

Additional Inherited Members

- Public Types inherited from Stroika::Foundation::Traversal::Range< T, TRAITS >
using value_type = T
 Range::value_type is the type of the contained elements of the range (say range of integers, value_type=int)
 

Detailed Description

template<typename T, typename TRAITS = RangeTraits::Default<T>>
class Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >

A DiscreteRange is a Range where the underlying endpoints are integral (discrete, not continuous); this implies you can iterate over the members of the range, and its endpoints are closed.

DiscreteRange<> is an immutable type (once constructed, will never change), except for allowing operator=..

Example Usage
vector<int> v = DiscreteRange<int>{1,10}.Elements ().As<vector<int>> ();
// equiv to vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
A DiscreteRange is a Range where the underlying endpoints are integral (discrete, not continuous); th...
nonvirtual Iterable< T > Elements() const
OR
for (auto i : DiscreteRange<int>{1,10}) {
...i = 1..10
}
OR
enum class Color { red, blue, green, Stroika_Define_Enum_Bounds (red, green) };
for (auto i : DiscreteRange<Color>::FullRange ().Elements ()) {
// iterate over each color - red, green, blue
}
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
static constexpr DiscreteRange FullRange()
Note
Since the default traits for an enum with Stroika type annotation (Stroika_Define_Enum_Bounds) provides the start/end, DiscreteRange<SOME_ENUM>::FullRange ().Elements () returns an iterable with all possible legal values of the enum.

Definition at line 75 of file DiscreteRange.h.

Constructor & Destructor Documentation

◆ DiscreteRange()

template<typename T , typename TRAITS = RangeTraits::Default<T>>
constexpr Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::DiscreteRange ( )
explicitconstexprdefault

DiscreteRange () with no arguments produces an empty sequence.

Precondition
begin <= end (after substitution of optional values)
src range must be eClosed on both sides

Member Function Documentation

◆ FullRange()

template<typename T , typename TRAITS >
constexpr DiscreteRange< T, TRAITS > Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::FullRange ( )
staticconstexpr

Like Range<>::FullRange () but returning a DiscreteRange<> type.

Definition at line 158 of file DiscreteRange.inl.

◆ Intersection()

template<typename T , typename TRAITS >
constexpr Range< T, TRAITS > Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::Intersection ( const Range< T, TRAITS > &  rhs) const
constexpr

Like Range<>::Intersection (), but returning a DiscreteRange<> type.

Definition at line 163 of file DiscreteRange.inl.

◆ UnionBounds()

template<typename T , typename TRAITS >
constexpr Range< T, TRAITS > Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::UnionBounds ( const Range< T, TRAITS > &  rhs) const
constexpr

Like Range<>::UnionBounds (), but returning a DiscreteRange<> type.

Definition at line 173 of file DiscreteRange.inl.

◆ GetNumberOfContainedPoints()

template<typename T , typename TRAITS >
constexpr DiscreteRange< T, TRAITS >::UnsignedDifferenceType Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::GetNumberOfContainedPoints ( ) const
constexpr

This returns the number of points from lower bound to upper bound inclusive. This equals GetDistanceSpanned () + 1 (roughly). If (empty ()) .... this returns 0;

Definition at line 184 of file DiscreteRange.inl.

◆ Offset()

template<typename T , typename TRAITS >
constexpr auto Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::Offset ( SignedDifferenceType  o) const
constexpr
Precondition
not empty
the DiscreteRange produced by applying the given offset to *this remains valid with respect to the constraints on this DiscreteRange.

Definition at line 194 of file DiscreteRange.inl.

◆ Elements()

template<typename T , typename TRAITS >
Iterable< T > Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::Elements ( ) const
Example Usage

Elements () makes no guarantees about whether or not modifications to the underlying DisjointDiscreteRange<> will appear in the Elements() Iterable<T>.

Note
Elements produces a generator, not an actual list of each item (internally). This should not be visible externally, except in how much memory or time is required to create an Elements() iterable for a large range (should be cheap).

Definition at line 200 of file DiscreteRange.inl.

◆ operator Iterable< T >()

template<typename T , typename TRAITS >
Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::operator Iterable< T > ( ) const
Aliases
Elements ()

Definition at line 205 of file DiscreteRange.inl.

◆ begin()

template<typename T , typename TRAITS >
Iterator< T > Stroika::Foundation::Traversal::DiscreteRange< T, TRAITS >::begin ( ) const
See also
Elements () - this produces a generator iterator, so should be quite cheap even for a large range.

Definition at line 210 of file DiscreteRange.inl.


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