-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcast.cpp
More file actions
executable file
·34 lines (28 loc) · 1.31 KB
/
Copy pathcast.cpp
File metadata and controls
executable file
·34 lines (28 loc) · 1.31 KB
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
// Copyright David Stone 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
export module bounded.cast;
import bounded.integer;
import bounded.comparison;
import bounded.normalize;
import bounded.safe_extreme;
import bounded.unchecked;
namespace bounded {
export template<auto new_minimum, auto minimum, auto maximum>
constexpr auto increase_min(integer<minimum, maximum> const & value) {
return ::bounded::assume_in_range(value, constant<safe_max(new_minimum, minimum)>, constant<maximum>);
}
export template<auto new_minimum, auto minimum, auto maximum>
constexpr auto increase_min(integer<minimum, maximum> const & value, unchecked_t) {
return integer<normalize<safe_max(new_minimum, minimum)>, maximum>(value, unchecked);
}
export template<auto new_maximum, auto minimum, auto maximum>
constexpr auto decrease_max(integer<minimum, maximum> const & value) {
return ::bounded::assume_in_range(value, constant<minimum>, constant<safe_min(new_maximum, maximum)>);
}
export template<auto new_maximum, auto minimum, auto maximum>
constexpr auto decrease_max(integer<minimum, maximum> const & value, unchecked_t) {
return integer<minimum, normalize<safe_min(new_maximum, maximum)>>(value, unchecked);
}
} // namespace bounded