File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ target_sources(bounded PUBLIC
51
51
cast.cpp
52
52
character.cpp
53
53
check_in_range.cpp
54
+ checked_bit_cast.cpp
54
55
clamp.cpp
55
56
common_type_and_value_category.cpp
56
57
comparison.cpp
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export import bounded.builtin_min_max_value;
15
15
export import bounded.cast;
16
16
export import bounded.character;
17
17
export import bounded.check_in_range;
18
+ export import bounded.checked_bit_cast;
18
19
export import bounded.clamp;
19
20
export import bounded.common_type_and_value_category;
20
21
export import bounded.comparison;
Original file line number Diff line number Diff line change
1
+ // Copyright David Stone 2024.
2
+ // Distributed under the Boost Software License, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at
4
+ // http://www.boost.org/LICENSE_1_0.txt)
5
+
6
+ export module bounded.checked_bit_cast;
7
+
8
+ import bounded.bounded_integer;
9
+ import bounded.check_in_range;
10
+
11
+ import std_module;
12
+
13
+ namespace bounded {
14
+
15
+ export template <bounded_integer T, typename Source>
16
+ constexpr auto checked_bit_cast (Source const source) -> T {
17
+ return bounded::check_in_range<T>(std::bit_cast<typename T::underlying_type>(source));
18
+ }
19
+
20
+ } // namespace bounded
You can’t perform that action at this time.
0 commit comments