19
19
namespace sus ::construct {
20
20
21
21
// / Specializing this class for `To` and `From` allows `To` to satisfy
22
- // / `AsBits <To, From>`.
22
+ // / `ToBits <To, From>`.
23
23
// /
24
24
// / # Examples
25
25
// /
26
26
// / To allow bitwise conversion to `Goat` from any type satisying a
27
27
// / concept `GoatLike`:
28
28
// / ```cpp
29
- // / // Satisfies AsBits <Goat, GoatLike>.
29
+ // / // Satisfies ToBits <Goat, GoatLike>.
30
30
// / template <class Goat, GoatLike G>
31
- // / struct AsBitsImpl <Goat, G> {
31
+ // / struct ToBitsImpl <Goat, G> {
32
32
// / constexpr static Goat from_bits(const G& g) noexcept { return ...; }
33
33
// / };
34
34
// / ```
35
35
// /
36
36
// / To receive something that can be bitwise converted to an `u32`.
37
37
// / ```cpp
38
- // / auto add = [](u32 a, const sus::construct::AsBits <u32> auto& b) -> u32 {
39
- // / return a.wrapping_add(sus::as_bits <u32>(b));
38
+ // / auto add = [](u32 a, const sus::construct::ToBits <u32> auto& b) -> u32 {
39
+ // / return a.wrapping_add(sus::to_bits <u32>(b));
40
40
// / };
41
41
// / sus::check(add(3_u32, -1_i32) == u32::MIN + 2);
42
42
// / ```
43
43
template <class To , class From >
44
- struct AsBitsImpl ;
44
+ struct ToBitsImpl ;
45
45
46
- // sus::construct::AsBits <T, T> trait for identity conversion.
46
+ // sus::construct::ToBits <T, T> trait for identity conversion.
47
47
template <class T >
48
- struct sus ::construct::AsBitsImpl <T, T> {
48
+ struct ToBitsImpl <T, T> {
49
49
constexpr static T from_bits (const T& from) noexcept { return from; }
50
50
};
51
51
52
- // / A type `T` that satisfies `AsBits <T, F>` can be constructed from `F` through
52
+ // / A type `T` that satisfies `ToBits <T, F>` can be constructed from `F` through
53
53
// / a bitwise conversion that preserves the bits but not the conceptual value of
54
54
// / `F`. The conversion may also truncate or extend `F` in order to do the
55
55
// / bitwise conversion to `T`.
@@ -59,9 +59,9 @@ struct sus::construct::AsBitsImpl<T, T> {
59
59
// / types to participate in deciding how and when bitwise converstions can be
60
60
// / performed.
61
61
template <class To , class From >
62
- concept AsBits = requires(const From& from) {
62
+ concept ToBits = requires(const From& from) {
63
63
{
64
- ::sus::construct::AsBitsImpl <To, From>::from_bits (from)
64
+ ::sus::construct::ToBitsImpl <To, From>::from_bits (from)
65
65
} noexcept -> std::same_as<To>;
66
66
};
67
67
@@ -71,10 +71,10 @@ concept AsBits = requires(const From& from) {
71
71
// /
72
72
// / To convert between types while preserving the meaning of the value, use
73
73
// / `sus::construct::Into` or `sus::construct::TryInto`. Usually prefer using
74
- // / `sus::into(x)` or `sus::try_into(x)` over `sus::as_bits <Y>(x)` as most code
74
+ // / `sus::into(x)` or `sus::try_into(x)` over `sus::to_bits <Y>(x)` as most code
75
75
// / is not doing bitwise manipulation.
76
76
// /
77
- // / The result of `as_bits ()` may be lossy. It may truncate bits from the input,
77
+ // / The result of `to_bits ()` may be lossy. It may truncate bits from the input,
78
78
// / or extend it.
79
79
// /
80
80
// / # Examples
@@ -83,16 +83,16 @@ concept AsBits = requires(const From& from) {
83
83
// / large positive number, and truncates 32 bits which loses the original value
84
84
// / as well.
85
85
// / ```cpp
86
- // / sus::check(u32::MAX == sus::as_bits <u32>(-1_i64));
86
+ // / sus::check(u32::MAX == sus::to_bits <u32>(-1_i64));
87
87
// / ```
88
88
template <class To , class From >
89
- constexpr inline To as_bits (const From& from) {
90
- return AsBitsImpl <To, From>::from_bits (from);
89
+ constexpr inline To to_bits (const From& from) {
90
+ return ToBitsImpl <To, From>::from_bits (from);
91
91
}
92
92
93
93
} // namespace sus::construct
94
94
95
- // Bring the as_bits () function into the `sus` namespace.
95
+ // Bring the to_bits () function into the `sus` namespace.
96
96
namespace sus {
97
- using ::sus::construct::as_bits ;
97
+ using ::sus::construct::to_bits ;
98
98
}
0 commit comments