2
2
3
3
#include " feature_test.hpp"
4
4
5
- #ifdef LIB_INTERVAL_TREE_CONCEPTS
6
- # include < type_traits>
7
- #endif
8
-
9
5
#include < cmath>
10
6
#include < algorithm>
7
+ #include < utility>
8
+ #include < type_traits>
11
9
12
10
namespace lib_interval_tree
13
11
{
@@ -69,10 +67,23 @@ namespace lib_interval_tree
69
67
}
70
68
71
69
template <typename numerical_type>
72
- static inline numerical_type size (numerical_type low, numerical_type high)
70
+ static inline typename std::enable_if<!std::is_floating_point<numerical_type>::value, numerical_type>::type
71
+ size (numerical_type low, numerical_type high)
73
72
{
74
73
return high - low + 1 ;
75
74
}
75
+
76
+ template <typename numerical_type>
77
+ #ifdef LIB_INTERVAL_TREE_CONCEPTS
78
+ requires std::is_floating_point_v<numerical_type>
79
+ static inline numerical_type
80
+ #else
81
+ static inline typename std::enable_if<std::is_floating_point<numerical_type>::value, numerical_type>::type
82
+ #endif
83
+ size (numerical_type low, numerical_type high)
84
+ {
85
+ return high - low;
86
+ }
76
87
};
77
88
// ()
78
89
struct open
@@ -90,27 +101,49 @@ namespace lib_interval_tree
90
101
}
91
102
92
103
template <typename numerical_type>
93
- static inline numerical_type size (numerical_type low, numerical_type high)
104
+ static inline typename std::enable_if<!std::is_floating_point<numerical_type>::value, numerical_type>::type
105
+ size (numerical_type low, numerical_type high)
94
106
{
95
107
return high - low - 1 ;
96
108
}
109
+
110
+ template <typename numerical_type>
111
+ #ifdef LIB_INTERVAL_TREE_CONCEPTS
112
+ requires std::is_floating_point_v<numerical_type>
113
+ static inline numerical_type
114
+ #else
115
+ static inline typename std::enable_if<std::is_floating_point<numerical_type>::value, numerical_type>::type
116
+ #endif
117
+ size (numerical_type low, numerical_type high)
118
+ {
119
+ return high - low;
120
+ }
97
121
};
98
122
// / [] and adjacent counts as overlapping
99
123
struct closed_adjacent
100
124
{
101
125
template <typename numerical_type>
126
+ #ifdef LIB_INTERVAL_TREE_CONCEPTS
127
+ requires std::is_integral_v<numerical_type>
128
+ #endif
102
129
static inline bool within (numerical_type low, numerical_type high, numerical_type p)
103
130
{
104
131
return (low <= p) && (p <= high);
105
132
}
106
133
107
134
template <typename numerical_type>
135
+ #ifdef LIB_INTERVAL_TREE_CONCEPTS
136
+ requires std::is_integral_v<numerical_type>
137
+ #endif
108
138
static inline bool overlaps (numerical_type l1, numerical_type h1, numerical_type l2, numerical_type h2)
109
139
{
110
140
return (l1 <= (h2 + 1 )) && ((l2 - 1 ) <= h1);
111
141
}
112
142
113
143
template <typename numerical_type>
144
+ #ifdef LIB_INTERVAL_TREE_CONCEPTS
145
+ requires std::is_integral_v<numerical_type>
146
+ #endif
114
147
static inline numerical_type size (numerical_type low, numerical_type high)
115
148
{
116
149
return high - low + 1 ;
@@ -123,6 +156,10 @@ namespace lib_interval_tree
123
156
open,
124
157
closed_adjacent
125
158
};
159
+
160
+ /* *
161
+ * @brief Do not use for floating point types
162
+ */
126
163
class dynamic
127
164
{
128
165
public:
0 commit comments