Skip to content

Commit 72b5116

Browse files
committed
Rename AsBits to ToBits
The conversion is owning to owning (cheap copy), not reference to reference or owning to reference. So it's a 'to' transformation.
1 parent 82442f3 commit 72b5116

File tree

7 files changed

+255
-255
lines changed

7 files changed

+255
-255
lines changed

subspace/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ if(${SUBSPACE_BUILD_TESTS})
225225
"choice/choice_types_unittest.cc"
226226
"choice/choice_unittest.cc"
227227
"convert/subclass_unittest.cc"
228-
"construct/as_bits_unittest.cc"
228+
"construct/to_bits_unittest.cc"
229229
"containers/array_unittest.cc"
230230
"containers/invalidation_off_size_unittest.cc"
231231
"containers/invalidation_on_size_unittest.cc"

subspace/construct/as_bits.h renamed to subspace/construct/to_bits.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@
1919
namespace sus::construct {
2020

2121
/// Specializing this class for `To` and `From` allows `To` to satisfy
22-
/// `AsBits<To, From>`.
22+
/// `ToBits<To, From>`.
2323
///
2424
/// # Examples
2525
///
2626
/// To allow bitwise conversion to `Goat` from any type satisying a
2727
/// concept `GoatLike`:
2828
/// ```cpp
29-
/// // Satisfies AsBits<Goat, GoatLike>.
29+
/// // Satisfies ToBits<Goat, GoatLike>.
3030
/// template <class Goat, GoatLike G>
31-
/// struct AsBitsImpl<Goat, G> {
31+
/// struct ToBitsImpl<Goat, G> {
3232
/// constexpr static Goat from_bits(const G& g) noexcept { return ...; }
3333
/// };
3434
/// ```
3535
///
3636
/// To receive something that can be bitwise converted to an `u32`.
3737
/// ```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));
4040
/// };
4141
/// sus::check(add(3_u32, -1_i32) == u32::MIN + 2);
4242
/// ```
4343
template <class To, class From>
44-
struct AsBitsImpl;
44+
struct ToBitsImpl;
4545

46-
// sus::construct::AsBits<T, T> trait for identity conversion.
46+
// sus::construct::ToBits<T, T> trait for identity conversion.
4747
template <class T>
48-
struct sus::construct::AsBitsImpl<T, T> {
48+
struct ToBitsImpl<T, T> {
4949
constexpr static T from_bits(const T& from) noexcept { return from; }
5050
};
5151

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
5353
/// a bitwise conversion that preserves the bits but not the conceptual value of
5454
/// `F`. The conversion may also truncate or extend `F` in order to do the
5555
/// bitwise conversion to `T`.
@@ -59,9 +59,9 @@ struct sus::construct::AsBitsImpl<T, T> {
5959
/// types to participate in deciding how and when bitwise converstions can be
6060
/// performed.
6161
template <class To, class From>
62-
concept AsBits = requires(const From& from) {
62+
concept ToBits = requires(const From& from) {
6363
{
64-
::sus::construct::AsBitsImpl<To, From>::from_bits(from)
64+
::sus::construct::ToBitsImpl<To, From>::from_bits(from)
6565
} noexcept -> std::same_as<To>;
6666
};
6767

@@ -71,10 +71,10 @@ concept AsBits = requires(const From& from) {
7171
///
7272
/// To convert between types while preserving the meaning of the value, use
7373
/// `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
7575
/// is not doing bitwise manipulation.
7676
///
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,
7878
/// or extend it.
7979
///
8080
/// # Examples
@@ -83,16 +83,16 @@ concept AsBits = requires(const From& from) {
8383
/// large positive number, and truncates 32 bits which loses the original value
8484
/// as well.
8585
/// ```cpp
86-
/// sus::check(u32::MAX == sus::as_bits<u32>(-1_i64));
86+
/// sus::check(u32::MAX == sus::to_bits<u32>(-1_i64));
8787
/// ```
8888
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);
9191
}
9292

9393
} // namespace sus::construct
9494

95-
// Bring the as_bits() function into the `sus` namespace.
95+
// Bring the to_bits() function into the `sus` namespace.
9696
namespace sus {
97-
using ::sus::construct::as_bits;
97+
using ::sus::construct::to_bits;
9898
}

subspace/construct/as_bits_unittest.cc renamed to subspace/construct/to_bits_unittest.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "subspace/construct/as_bits.h"
15+
#include "subspace/construct/to_bits.h"
1616

1717
#include "googletest/include/gtest/gtest.h"
1818
#include "subspace/prelude.h"
1919

2020
namespace {
2121

22-
TEST(AsBits, Example_Concept) {
23-
auto add = [](u32 a, const sus::construct::AsBits<u32> auto& b) -> u32 {
24-
return a.wrapping_add(sus::as_bits<u32>(b));
22+
TEST(ToBits, Example_Concept) {
23+
auto add = [](u32 a, const sus::construct::ToBits<u32> auto& b) -> u32 {
24+
return a.wrapping_add(sus::to_bits<u32>(b));
2525
};
2626
sus::check(add(3_u32, -1_i32) == u32::MIN + 2u);
2727
}
2828

29-
TEST(AsBits, Example_Function) {
30-
sus::check(u32::MAX == sus::as_bits<u32>(-1_i64));
29+
TEST(ToBits, Example_Function) {
30+
sus::check(u32::MAX == sus::to_bits<u32>(-1_i64));
3131
}
3232

3333
} // namespace

0 commit comments

Comments
 (0)