cpp-common/bt2c/std-int.hpp: use dedicated enum. instead of `bool`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 May 2024 19:41:10 +0000 (15:41 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
This makes the code clearer, for example

    bt2c::StdIntT<32, bt2c::Signedness::Signed>

vs.

    bt2c::StdIntT<32, true>

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icbb718dd36e11d5e072c7fc4b58fc2d4ca090d58
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12708

src/cpp-common/bt2c/std-int.hpp

index 2fe35353449745e788fdb7a76e838e92299aa6f5..c77d1a2ad39d4a7c3e5da252d7c3210dbaeb1de5 100644 (file)
 #include <cstdint>
 
 namespace bt2c {
+
+/*
+ * Whether or not an integer is signed.
+ */
+enum class Signedness
+{
+    Unsigned,
+    Signed,
+};
+
 namespace internal {
 
-template <std::size_t LenBitsV, bool IsSignedV>
+template <std::size_t LenBitsV, Signedness SignednessV>
 struct StdIntTBase;
 
 template <>
-struct StdIntTBase<8, true>
+struct StdIntTBase<8, Signedness::Signed>
 {
     using Type = std::int8_t;
 };
 
 template <>
-struct StdIntTBase<8, false>
+struct StdIntTBase<8, Signedness::Unsigned>
 {
     using Type = std::uint8_t;
 };
 
 template <>
-struct StdIntTBase<16, true>
+struct StdIntTBase<16, Signedness::Signed>
 {
     using Type = std::int16_t;
 };
 
 template <>
-struct StdIntTBase<16, false>
+struct StdIntTBase<16, Signedness::Unsigned>
 {
     using Type = std::uint16_t;
 };
 
 template <>
-struct StdIntTBase<32, true>
+struct StdIntTBase<32, Signedness::Signed>
 {
     using Type = std::int32_t;
 };
 
 template <>
-struct StdIntTBase<32, false>
+struct StdIntTBase<32, Signedness::Unsigned>
 {
     using Type = std::uint32_t;
 };
 
 template <>
-struct StdIntTBase<64, true>
+struct StdIntTBase<64, Signedness::Signed>
 {
     using Type = std::int64_t;
 };
 
 template <>
-struct StdIntTBase<64, false>
+struct StdIntTBase<64, Signedness::Unsigned>
 {
     using Type = std::uint64_t;
 };
@@ -67,14 +77,14 @@ struct StdIntTBase<64, false>
 
 /*
  * Standard fixed-length integer type `Type` of length `LenBitsV` bits
- * and signedness `IsSignedV`.
+ * and signedness `SignednessV`.
  *
  * `LenBitsV` must be one of 8, 16, 32, or 64.
  *
- * For example, `StdIntT<32, true>` is `std::int32_t`.
+ * For example, `StdIntT<32, Signedness::Signed>` is `std::int32_t`.
  */
-template <std::size_t LenBitsV, bool IsSignedV>
-using StdIntT = typename internal::StdIntTBase<LenBitsV, IsSignedV>::Type;
+template <std::size_t LenBitsV, Signedness SignednessV>
+using StdIntT = typename internal::StdIntTBase<LenBitsV, SignednessV>::Type;
 
 } /* namespace bt2c */
 
This page took 0.026045 seconds and 4 git commands to generate.