17concept IntervalPt = std::integral<T> && !std::same_as<char,T>;
35 template<std::input_iterator I>
36 C_Intervals(I start, I
end)
requires std::same_as<char, std::remove_cvref_t<
decltype(*start)>>
41 template<std::input_iterator I>
43 std::same_as<
value_type, std::remove_cvref_t<
decltype(*start)>> ||
45 !std::same_as<char,std::remove_cvref_t<
decltype(*start)>> &&
46 std::integral<std::remove_cvref_t<
decltype(*start)>> &&
47 std::cmp_less_equal(std::numeric_limits<T>::min(), std::numeric_limits<std::remove_cvref_t<
decltype(*start)>>::min()) &&
48 std::cmp_less_equal(std::numeric_limits<std::remove_cvref_t<
decltype(*start)>>::max(), std::numeric_limits<T>::max())
66 bool empty()
const {
return m_Intervals.empty(); }
67 size_t size()
const {
return m_Intervals.size(); }
76 std::vector<value_type> m_Intervals;
82template<IntervalPt T,
class charT,
class traits=std::
char_traits<
charT>>
83std::basic_ostream<charT,traits> &
84operator<<(std::basic_ostream<charT,traits> &out,
const C_Intervals<T> &x)
89 out <<(first?
"{[":
", [") <<i.first <<
',' <<i.second <<
']';
101template<IntervalPt T>
104 m_Intervals.emplace_back(
id,
id);
107template<IntervalPt T>
110 if (i.first > i.second)
113 m_Intervals.emplace_back(i);
116template<IntervalPt T>
119 decltype(m_Intervals) dst;
121 ia =other.m_Intervals.begin(), ea =other.m_Intervals.end(),
122 ib =m_Intervals.begin(), eb =m_Intervals.end();
125 bool tempInUse =
false;
126 while (ia != ea && ib != eb)
128 if (ia->first > ib->first)
134 if (ia->second >= ib->second)
137 else if (ia->second < ib->first && ia->second +1 < ib->first)
141 dst.emplace_back(*ia);
145 if (temp.second +1 >= ia->first)
147 temp.second = ia->second;
148 dst.emplace_back(temp);
152 dst.emplace_back(temp);
153 dst.emplace_back(*ia);
164 temp.first = ia->first;
167 temp.second = ib->second;
182 if (temp.second < ia->first && temp.second +1 < ia->first)
185 temp.second = ia->second;
188 dst.emplace_back(temp);
190 dst.insert(dst.end(), ia, ea);
191 dst.swap(m_Intervals);
194template<IntervalPt T>
197 decltype(m_Intervals) dst;
203 while (ia != ea && ib != eb)
205 if (ia->first > ib->first)
211 if (ia->second >= ib->second)
213 dst.emplace_back(*ib++);
214 else if (ia->second < ib->first)
220 dst.emplace_back(ib->first, ia->second);
224 dst.swap(m_Intervals);
227template<IntervalPt T>
230 auto ib =other.m_Intervals.begin(),
231 eb =other.m_Intervals.end();
233 for (
auto ia =m_Intervals.begin(); ia != m_Intervals.end() && ib != eb;)
235 if (ib->second < ia->first)
244 if (ib->first <= ia->first)
246 if (ia->second <= ib->second)
248 ia = m_Intervals.erase(ia);
252 ia->first = ib->second +1;
258 if (ia->second <= ib->second)
260 if (ia->second >= ib->first)
261 ia->second = ib->first -1;
267 ia = m_Intervals.insert(ia,
value_type(ia->first, ib->first-1));
268 (++ia)->first = ib->second +1;
275template<IntervalPt T>
278 if (m_Intervals.empty())
280 m_Intervals.emplace_back(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
283 decltype(m_Intervals) dst;
285 t.first = std::numeric_limits<T>::min();
286 for (
const auto &i: m_Intervals)
288 if (i.first > std::numeric_limits<T>::min())
290 t.second = i.first -1;
293 t.first = i.second +1;
295 if (t.first < std::numeric_limits<T>::max())
297 t.second = std::numeric_limits<T>::max();
300 dst.swap(m_Intervals);
#define RUNTIME_ERROR(fmtStr,...)
Wrap FILE(DATE)#__LINE__ FUNCTION: msg into std::runtime_error.
void operator=(const C_Intervals &other)
C_Intervals(const C_Intervals &other)
C_Intervals(T start, T end)
void operator=(C_Intervals &&other)
C_Intervals(I start, I end)
void operator-=(const C_Intervals &other)
C_Intervals(C_Intervals &&other)
void swap(C_Intervals &other)
std::pair< T, T > value_type
std::vector< value_type >::const_iterator const_iterator
C_Intervals(I start, I end)
const_iterator end() const
void operator|=(const C_Intervals &other)
const_iterator begin() const
void operator&=(const C_Intervals &other)
bool operator==(const C_Intervals &other) const
THE common namespace of bux library.
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &out, const C_Intervals< T > &x)