A sequence of contiguous ranges of integral numbers. More...
#include <IntegerRanges.h>
Classes | |
struct | Range_t |
Public Types | |
using | Data_t = T |
Type of data for the range set. More... | |
Public Member Functions | |
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 > |
Queries | |
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... | |
Protected Member Functions | |
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 | |
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... | |
Private Attributes | |
std::vector< Range_t > | fRanges |
List of current ranges. 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 [.
Definition at line 29 of file IntegerRanges.h.
using icarus::details::IntegerRangesBase< T >::Data_t = T |
Type of data for the range set.
Definition at line 79 of file IntegerRanges.h.
|
protecteddefault |
Default constructor: starts with no elements.
|
protected |
Constructor for the derived classes.
Definition at line 300 of file IntegerRanges.h.
|
noexcept |
Removes all the entries and makes the set as default-constructed.
Definition at line 306 of file IntegerRanges.h.
|
staticprotected |
Fills the ranges.
auto icarus::details::IntegerRangesBase< T >::compactRange | ( | BIter | b, |
EIter | e | ||
) | -> std::vector<Range_t> |
Definition at line 341 of file IntegerRanges.h.
void icarus::details::IntegerRangesBase< T >::dump | ( | std::ostream & | out, |
std::string const & | sep = " " , |
||
std::string const & | inRangeSep = "--" |
||
) | const |
Prints the range into the specified stream.
out | the stream to print into |
sep | separator between ranges |
inRangeSep | separator between lower and higher limit of each range |
Definition at line 400 of file IntegerRanges.h.
|
noexcept |
Returns whether there is any element in the range set.
Definition at line 312 of file IntegerRanges.h.
|
staticprotectednoexcept |
|
noexcept |
Returns the number of non-contiguous ranges in the set.
Definition at line 328 of file IntegerRanges.h.
|
staticprotectednoexcept |
|
noexcept |
Returns an iterable object with all sorted ranges as elements.
|
noexcept |
Returns the number of elements in the ranges (gaps excluded).
Definition at line 318 of file IntegerRanges.h.
|
private |
List of current ranges.
Definition at line 158 of file IntegerRanges.h.