-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrange.h
68 lines (54 loc) · 1.95 KB
/
range.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef RO_RANGE_H
#define RO_RANGE_H
#include <ro/numeric_range.h>
#include <ro/iterator_range.h>
#include <ro/mapped_range.h>
#include <ro/predicated_range.h>
#include <ro/rand_range.h>
namespace {
namespace ro {
///////////////////////////////////////////////////////////////// OPERATORS - FREE FUNCTIONS
// FIXME: this really should be 2 separate funcs for chain
// and numeric to make corresponding includes not to depend on range.h
//// it - n
template <class RgI>
eIF<
is_ro_range_iterator<RgI>::value && is_random_access_iterator<RgI>::value
, rm_ref<decltype(std::declval<RgI>().current-1, std::declval<RgI>())>
>
operator- (RgI it, typename RgI::difference_type n) {
it.current-=n; return std::move(it);
}
//// it + n
template <class RgI>
eIF<
is_ro_range_iterator<RgI>::value && is_random_access_iterator<RgI>::value
, rm_ref<decltype(std::declval<RgI>().current+1, std::declval<RgI>())>
>
operator+ (RgI it, typename RgI::difference_type n) {
it.current+=n; return std::move(it);
}
//// n + it
template <class RgI>
eIF<
( is_numeric_range_iterator<RgI>::value || is_ro_range_iterator<RgI>::value )
&& is_random_access_iterator<RgI>::value
, rm_ref<decltype(1 + std::declval<RgI>().current, std::declval<RgI>())>
>
operator+ (typename RgI::difference_type n, RgI it) {
it.current+=n; return std::move(it);
}
//// it - it
template <class RgI>
eIF <
( is_numeric_range_iterator<RgI>::value || is_ro_range_iterator<RgI>::value )
&& is_random_access_iterator<RgI>::value
, rm_ref<decltype(std::declval<RgI>().current - std::declval<RgI>().current, typename RgI::difference_type())>
>
operator- (const RgI& it1, const RgI& it2) {
return it1.current-it2.current;
}
////////////////////////////////////////////////////////////////////////////////////////////
} // ro namespace
}
#endif // RO_RANGE_H