From 619481cbc383fd7c2e0fb5cf795150e467d98302 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 10 May 2024 15:41:10 -0400 Subject: [PATCH] cpp-common/bt2c/std-int.hpp: use dedicated enum. instead of `bool` This makes the code clearer, for example bt2c::StdIntT<32, bt2c::Signedness::Signed> vs. bt2c::StdIntT<32, true> Signed-off-by: Philippe Proulx Change-Id: Icbb718dd36e11d5e072c7fc4b58fc2d4ca090d58 Reviewed-on: https://review.lttng.org/c/babeltrace/+/12708 --- src/cpp-common/bt2c/std-int.hpp | 36 +++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/cpp-common/bt2c/std-int.hpp b/src/cpp-common/bt2c/std-int.hpp index 2fe35353..c77d1a2a 100644 --- a/src/cpp-common/bt2c/std-int.hpp +++ b/src/cpp-common/bt2c/std-int.hpp @@ -10,55 +10,65 @@ #include namespace bt2c { + +/* + * Whether or not an integer is signed. + */ +enum class Signedness +{ + Unsigned, + Signed, +}; + namespace internal { -template +template 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 -using StdIntT = typename internal::StdIntTBase::Type; +template +using StdIntT = typename internal::StdIntTBase::Type; } /* namespace bt2c */ -- 2.34.1