All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Private Types | List of all members
icarus::IntegerRanges< T, CheckGrowing > Class Template Reference

A sequence of contiguous ranges of integral numbers. More...

#include <IntegerRanges.h>

Inheritance diagram for icarus::IntegerRanges< T, CheckGrowing >:
icarus::details::IntegerRangesBase< T >

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_tcompactRange (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...
 

Detailed Description

template<typename T = int, bool CheckGrowing = false>
class icarus::IntegerRanges< T, CheckGrowing >

A sequence of contiguous ranges of integral numbers.

Template Parameters
Ttype of the integral numbers
CheckGrowingif 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:

std::array data { 1, 2, 4, 5, 6, 8, 10 };
std::cout << "Ranges: " << ranges << std::endl;

will print something like Ranges: 1 2 4--6 8 10.

Definition at line 41 of file IntegerRanges.h.

Member Typedef Documentation

template<typename T = int, bool CheckGrowing = false>
using icarus::IntegerRanges< T, CheckGrowing >::Base_t = icarus::details::IntegerRangesBase<T>
private

Definition at line 196 of file IntegerRanges.h.

template<typename T = int, bool CheckGrowing = false>
using icarus::IntegerRanges< T, CheckGrowing >::Data_t = typename Base_t::Data_t

Definition at line 201 of file IntegerRanges.h.

Constructor & Destructor Documentation

template<typename T = int, bool CheckGrowing = false>
icarus::IntegerRanges< T, CheckGrowing >::IntegerRanges ( )
default

Default constructor: an empty set of ranges.

template<typename T , bool CheckGrowing>
template<typename BIter , typename EIter >
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.

422  : Base_t{ Base_t::template compactRange<CheckGrowing>(b, e) }
423  {}
icarus::details::IntegerRangesBase< T > Base_t
do i e
template<typename T , bool CheckGrowing>
icarus::IntegerRanges< T, CheckGrowing >::IntegerRanges ( std::initializer_list< Data_t data)

Definition at line 429 of file IntegerRanges.h.

430  : IntegerRanges(data.begin(), data.end()) {}
IntegerRanges()=default
Default constructor: an empty set of ranges.

Member Data Documentation

template<typename T = int, bool CheckGrowing = false>
constexpr bool icarus::IntegerRanges< T, CheckGrowing >::IsChecked = CheckGrowing
static

Definition at line 199 of file IntegerRanges.h.


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