Skip to content

Commit 4b4fef4

Browse files
committed
Support arbitrary integral types in check_in_range
1 parent 5d42fce commit 4b4fef4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

source/bounded/check_in_range.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ auto to_string(bounded_integer auto const x) {
4747
}
4848

4949
export template<typename Exception = std::range_error>
50-
constexpr auto check_in_range(integral auto const value, bounded_integer auto const minimum, bounded_integer auto const maximum) {
50+
constexpr auto check_in_range(integral auto const value, integral auto const minimum, integral auto const maximum) {
5151
if (minimum <= value and value <= maximum) {
5252
return ::bounded::detail::assume_in_range_impl(value, minimum, maximum);
5353
} else {
@@ -57,7 +57,11 @@ constexpr auto check_in_range(integral auto const value, bounded_integer auto co
5757

5858
export template<typename Target, typename Exception = std::range_error>
5959
constexpr auto check_in_range(integral auto const value) {
60-
return ::bounded::check_in_range<Exception>(value, numeric_traits::min_value<Target>, numeric_traits::max_value<Target>);
60+
return static_cast<Target>(::bounded::check_in_range<Exception>(
61+
value,
62+
numeric_traits::min_value<Target>,
63+
numeric_traits::max_value<Target>
64+
));
6165
}
6266

6367
} // namespace bounded

0 commit comments

Comments
 (0)