@@ -193,16 +193,35 @@ namespace lib_interval_tree
193
193
194
194
template <typename numerical_type>
195
195
#ifdef LIB_INTERVAL_TREE_CONCEPTS
196
- requires (!std::is_floating_point_v<numerical_type>)
196
+ requires (!std::is_floating_point_v<numerical_type> && std::is_signed_v<numerical_type> )
197
197
static inline numerical_type
198
198
#else
199
- static inline typename std::enable_if<!std::is_floating_point<numerical_type>::value, numerical_type>::type
199
+ static inline typename std::enable_if<
200
+ !std::is_floating_point<numerical_type>::value && std::is_signed<numerical_type>::value,
201
+ numerical_type>::type
200
202
#endif
201
203
size (numerical_type low, numerical_type high)
202
204
{
203
205
return high - low - 1 ;
204
206
}
205
207
208
+ template <typename numerical_type>
209
+ #ifdef LIB_INTERVAL_TREE_CONCEPTS
210
+ requires (!std::is_floating_point_v<numerical_type> && std::is_unsigned_v<numerical_type>)
211
+ static inline numerical_type
212
+ #else
213
+ static inline typename std::enable_if<
214
+ !std::is_floating_point<numerical_type>::value && std::is_unsigned<numerical_type>::value,
215
+ numerical_type>::type
216
+ #endif
217
+ size (numerical_type low, numerical_type high)
218
+ {
219
+ if (high > low)
220
+ return high - low - 1 ;
221
+ else
222
+ return 0 ;
223
+ }
224
+
206
225
template <typename numerical_type>
207
226
#ifdef LIB_INTERVAL_TREE_CONCEPTS
208
227
requires std::is_floating_point_v<numerical_type>
@@ -393,7 +412,13 @@ namespace lib_interval_tree
393
412
394
413
const auto highToClosed = [](auto const & ival) {
395
414
if (ival.right_border () == interval_border::open)
415
+ {
416
+ INTERVAL_TREE_CONSTEXPR_IF (std::is_unsigned<typename interval_type::value_type>::value)
417
+ {
418
+ return ival.high () > 0 ? ival.high () - 1 : 0 ;
419
+ }
396
420
return ival.high () - 1 ;
421
+ }
397
422
return ival.high ();
398
423
};
399
424
@@ -442,11 +467,33 @@ namespace lib_interval_tree
442
467
return 0 ;
443
468
444
469
value_type adjusted_low = ival1.left_border () == interval_border::open ? ival1.low () + 1 : ival1.low ();
445
- value_type adjusted_high = ival1.right_border () == interval_border::open ? ival1.high () - 1 : ival1.high ();
470
+
471
+ value_type adjusted_high = [&]() {
472
+ INTERVAL_TREE_CONSTEXPR_IF (std::is_unsigned<value_type>::value)
473
+ {
474
+ return ival1.right_border () == interval_border::open ? (ival1.high () > 0 ? ival1.high () - 1 : 0 )
475
+ : ival1.high ();
476
+ }
477
+ else
478
+ {
479
+ return ival1.right_border () == interval_border::open ? ival1.high () - 1 : ival1.high ();
480
+ }
481
+ }();
482
+
446
483
value_type other_adjusted_low =
447
484
ival2.left_border () == interval_border::open ? ival2.low () + 1 : ival2.low ();
448
- value_type other_adjusted_high =
449
- ival2.right_border () == interval_border::open ? ival2.high () - 1 : ival2.high ();
485
+
486
+ value_type other_adjusted_high = [&]() {
487
+ INTERVAL_TREE_CONSTEXPR_IF (std::is_unsigned<value_type>::value)
488
+ {
489
+ return ival2.right_border () == interval_border::open ? (ival2.high () > 0 ? ival2.high () - 1 : 0 )
490
+ : ival2.high ();
491
+ }
492
+ else
493
+ {
494
+ return ival2.right_border () == interval_border::open ? ival2.high () - 1 : ival2.high ();
495
+ }
496
+ }();
450
497
451
498
if (adjusted_high < other_adjusted_low)
452
499
return other_adjusted_low - adjusted_high;
@@ -540,7 +587,13 @@ namespace lib_interval_tree
540
587
? &ival1
541
588
: &ival2;
542
589
543
- const auto openAdjusted = rightOpenInterval->high () - 1 ;
590
+ const auto openAdjusted = [&]() {
591
+ INTERVAL_TREE_CONSTEXPR_IF (std::is_unsigned<typename interval_type::value_type>::value)
592
+ {
593
+ return rightOpenInterval->high () > 0 ? rightOpenInterval->high () - 1 : 0 ;
594
+ }
595
+ return rightOpenInterval->high () - 1 ;
596
+ }();
544
597
545
598
if (openAdjusted == rightClosedInterval->high ())
546
599
{
0 commit comments