11 #ifndef ICARUSALG_UTILITIES_INTEGERRANGES_H
12 #define ICARUSALG_UTILITIES_INTEGERRANGES_H
17 #include <initializer_list>
20 #include <type_traits>
41 template <
typename T =
int,
bool CheckGrowing = false>
class IntegerRanges;
43 template <
bool CheckGrowing = true ,
typename Coll>
48 template <
typename T,
bool CheckGrowing>
49 std::ostream&
operator<<
52 template <
typename T,
bool CheckGrowing>
53 std::ostream&
operator<<
73 template <
typename T >
76 (std::is_integral_v<T>,
"IntegerRanges only support integral types.");
98 void dump(
std::ostream& out,
std::
string const& sep = "--") const;
104 void clear() noexcept;
112 bool empty() const noexcept;
115 std::
size_t size() const noexcept;
121 decltype(auto)
ranges() const noexcept;
132 std::
string const& sep = " ",
std::
string const& inRangeSep = "--"
146 template <
bool CheckGrowing, typename BIter, typename EIter>
193 template <typename T ,
bool CheckGrowing >
199 static constexpr
bool IsChecked = CheckGrowing;
207 template <
typename BIter,
typename EIter>
217 template <
bool CheckGrowing,
typename Coll>
232 template <
typename T >
240 template <
typename T >
243 {
return lower ==
upper; }
247 template <
typename T >
250 {
return upper -
lower; }
254 template <
typename T >
261 template <
typename T >
268 template <
typename T >
270 (std::ostream& out, std::string
const& sep, std::string
const& simpleSep)
282 out << (isTwo()? simpleSep: sep) << icarus::details::IntegerRangesBase<T>::minusOne(
upper);
289 template <
typename T >
291 (std::ostream& out, std::string
const& sep )
const
292 {
dump(out, sep, sep); }
298 template <
typename T >
305 template <
typename T >
311 template <
typename T >
317 template <
typename T >
321 [](std::size_t
s,
Range_t const&
r){
return s +
r.size(); });
327 template <
typename T >
333 template <
typename T >
339 template <
typename T >
340 template <
bool CheckGrowing,
typename BIter,
typename EIter>
342 -> std::vector<Range_t>
344 if (b ==
e)
return {};
346 std::vector<Range_t>
ranges;
357 if (*iPrev == *it)
continue;
358 if constexpr (CheckGrowing) {
361 throw std::runtime_error{
"icarus::IntegerRanges"
362 " initialized with non-monotonically growing sequence ("
370 auto const nextExpected =
plusOne(*iPrev);
372 if ((it !=
e) && (*it == nextExpected))
continue;
374 ranges.emplace_back(*iFirst, nextExpected);
385 template <
typename T >
392 template <
typename T >
399 template <
typename T >
402 std::string
const& sep ,
403 std::string
const& inRangeSep
409 auto const rend =
fRanges.end();
410 iRange->dump(out, inRangeSep, sep);
411 while (++iRange != rend) iRange->dump(out << sep, inRangeSep, sep);
419 template <
typename T ,
bool CheckGrowing >
420 template <
typename BIter,
typename EIter>
422 :
Base_t{ Base_t::template compactRange<CheckGrowing>(b,
e) }
427 template <
typename T ,
bool CheckGrowing >
429 (std::initializer_list<Data_t> data)
434 template <
typename T,
bool CheckGrowing>
435 std::ostream& icarus::operator<<
437 {
r.dump(out);
return out; }
441 template <
typename T,
bool CheckGrowing>
442 std::ostream& icarus::operator<<
444 {
r.dump(out);
return out; }
450 #endif // ICARUSALG_UTILITIES_INTEGERRANGES_H
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
static std::vector< Range_t > compactRange(BIter b, EIter e)
Fills the ranges.
std::size_t nRanges() const noexcept
Returns the number of non-contiguous ranges in the set.
T Data_t
Type of data for the range set.
constexpr Range_t() noexcept=default
static constexpr Data_t plusOne(Data_t value) noexcept
Returns value incremented by 1.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
IntegerRanges< typename Coll::value_type, CheckGrowing > makeIntegerRanges(Coll const &coll)
void clear() noexcept
Removes all the entries and makes the set as default-constructed.
constexpr bool empty() const noexcept
void dump(std::ostream &out, std::string const &sep, std::string const &simpleSep) const
auto end(FixedBins< T, C > const &) noexcept
constexpr std::size_t size() const noexcept
std::size_t size() const noexcept
Returns the number of elements in the ranges (gaps excluded).
IntegerRangesBase()=default
Default constructor: starts with no elements.
static constexpr Data_t minusOne(Data_t value) noexcept
Returns value decremented by 1.
auto begin(FixedBins< T, C > const &) noexcept
constexpr bool isTwo() const noexcept
bool empty() const noexcept
Returns whether there is any element in the range set.
IntegerRanges()=default
Default constructor: an empty set of ranges.
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
A sequence of contiguous ranges of integral numbers.
constexpr bool isOne() const noexcept
std::vector< Range_t > fRanges
List of current ranges.
A sequence of contiguous ranges of integral numbers.
void dump(std::ostream &out, std::string const &sep=" ", std::string const &inRangeSep="--") const
decltype(auto) ranges() const noexcept
Returns an iterable object with all sorted ranges as elements.
std::ostream & operator<<(std::ostream &out, typename IntegerRangesBase< T >::Data_t const &range)