blob: 99ff5a25cd40f5cadd2d230ed1a6f287acfdc49e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#ifndef iUCKfY0lAetXcXu8Ykh6wMB3KhQ
#define iUCKfY0lAetXcXu8Ykh6wMB3KhQ
#include <set>
#include <boost/xpressive/xpressive_static.hpp>
#include <boost/xpressive/regex_actions.hpp>
namespace IdListImpl {
using namespace boost::xpressive;
struct push_impl {
typedef void result_type;
template<typename Set, class Value>
void operator()(Set &s, Value const &from, Value const &until) const {
for (Value i = from; i <= until; ++i)
s.insert(i);
}
};
function<push_impl>::type const pushRange = {{}};
template<typename ID>
struct IdList : std::set<ID> {
explicit IdList(char *s = (char*) "") {
cregex number = (s1= +_d)
[insert(boost::xpressive::ref(*this), as<ID>(s1))];
cregex range = ((s1= +_d) >> as_xpr('-') >> (s2= +_d))
[pushRange(boost::xpressive::ref(*this), as<ID>(s1), as<ID>(s2))];
cregex list = *((range | number) >> *( as_xpr(',') >> (range | number)));
assert(regex_match(s, list));
}
template<typename OtherID>
IdList(IdList<OtherID> &src) {
for (auto i : src) {
assert(i <= std::numeric_limits<ID>::max());
this->insert(i);
}
}
};
} // IdListImpl
using IdListImpl::IdList;
#endif // iUCKfY0lAetXcXu8Ykh6wMB3KhQ
|