A sequence of contiguous ranges of integral numbers. More...
#include <IntegerRanges.h>
Public Types | |
using | Data_t = typename Base_t::Data_t |
Public Types inherited from icarus::details::IntegerRangesBase< T > | |
using | Data_t = T |
Type of data for the range set. More... | |
Public Member Functions | |
IntegerRanges ()=default | |
Default constructor: an empty set of ranges. More... | |
template<typename BIter , typename EIter > | |
IntegerRanges (BIter b, EIter e) | |
Constructor: range from the values pointed between b and e iterators. More... | |
IntegerRanges (std::initializer_list< Data_t > data) | |
Public Member Functions inherited from icarus::details::IntegerRangesBase< T > | |
void | clear () noexcept |
Removes all the entries and makes the set as default-constructed. More... | |
void | dump (std::ostream &out, std::string const &sep=" ", std::string const &inRangeSep="--") const |
template<bool CheckGrowing, typename BIter , typename EIter > | |
auto | compactRange (BIter b, EIter e) -> std::vector< Range_t > |
bool | empty () const noexcept |
Returns whether there is any element in the range set. More... | |
std::size_t | size () const noexcept |
Returns the number of elements in the ranges (gaps excluded). More... | |
std::size_t | nRanges () const noexcept |
Returns the number of non-contiguous ranges in the set. More... | |
decltype(auto) | ranges () const noexcept |
Returns an iterable object with all sorted ranges as elements. More... | |
Static Public Attributes | |
static constexpr bool | IsChecked = CheckGrowing |
Private Types | |
using | Base_t = icarus::details::IntegerRangesBase< T > |
Additional Inherited Members | |
Protected Member Functions inherited from icarus::details::IntegerRangesBase< T > | |
IntegerRangesBase ()=default | |
Default constructor: starts with no elements. More... | |
IntegerRangesBase (std::vector< Range_t > ranges) | |
Constructor for the derived classes. More... | |
Static Protected Member Functions inherited from icarus::details::IntegerRangesBase< T > | |
template<bool CheckGrowing, typename BIter , typename EIter > | |
static std::vector< Range_t > | compactRange (BIter b, EIter e) |
Fills the ranges. More... | |
static constexpr Data_t | plusOne (Data_t value) noexcept |
Returns value incremented by 1. More... | |
static constexpr Data_t | minusOne (Data_t value) noexcept |
Returns value decremented by 1. More... | |
A sequence of contiguous ranges of integral numbers.
T | type of the integral numbers |
CheckGrowing | if true , checks will be performed on construction |
This class parses a sequence in input grouping the consecutive elements. The current interface is very simple, allowing only for query of groups ("ranges") and printing to a stream. The input is required and assumed to be a monotonously growing sequence, with the exception that duplicate consecutive entries are allowed (and ignored).
Each range is stored as a semi-open interval: [ lower, upper [.
If CheckGrowing
is true
, on input an exception will be thrown if the input is not strictly sorted (but duplicate elements are still allowed).
Example of usage:
will print something like Ranges: 1 2 4--6 8 10
.
Definition at line 41 of file IntegerRanges.h.
|
private |
Definition at line 196 of file IntegerRanges.h.
using icarus::IntegerRanges< T, CheckGrowing >::Data_t = typename Base_t::Data_t |
Definition at line 201 of file IntegerRanges.h.
|
default |
Default constructor: an empty set of ranges.
icarus::IntegerRanges< T, CheckGrowing >::IntegerRanges | ( | BIter | b, |
EIter | e | ||
) |
Constructor: range from the values pointed between b
and e
iterators.
Definition at line 421 of file IntegerRanges.h.
icarus::IntegerRanges< T, CheckGrowing >::IntegerRanges | ( | std::initializer_list< Data_t > | data | ) |
Definition at line 429 of file IntegerRanges.h.
|
static |
Definition at line 199 of file IntegerRanges.h.