Skip to content

Commit d467e93

Browse files
committed
Common: EnumFlags fix max rep.
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent f126dba commit d467e93

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Common/Utils/include/CommonUtils/EnumFlags.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ struct FlagsHelper final {
154154
}
155155
return values;
156156
}
157-
static constexpr auto Values{getValues(std::make_index_sequence<MaxScan - MinScan - MarginScan>())}; // Enum Values
158-
static constexpr auto count() noexcept { return Values.size(); } // Number of enum members
159-
static constexpr auto Min_v{Values.front()}; // Enum first entry
160-
static constexpr auto Max_v{Values.back()}; // Enum last entry
161-
static constexpr auto Min_u_v{static_cast<size_t>(Min_v)}; // Enum first entry as size_t
162-
static constexpr auto Max_u_v{static_cast<size_t>(Max_v)}; // Enum last entry as size_t
163-
static constexpr bool isContinuous() noexcept { return (Max_u_v - Min_u_v + 1) == count(); } // Is the enum continuous
164-
static constexpr uint64_t MaxRep{(Max_u_v >= 64) ? std::numeric_limits<uint64_t>::max() : (1ULL << Max_u_v) - 1}; // largest representable value
157+
static constexpr auto Values{getValues(std::make_index_sequence<MaxScan - MinScan - MarginScan>())}; // Enum Values
158+
static constexpr auto count() noexcept { return Values.size(); } // Number of enum members
159+
static constexpr auto Min_v{Values.front()}; // Enum first entry
160+
static constexpr auto Max_v{Values.back()}; // Enum last entry
161+
static constexpr auto Min_u_v{static_cast<size_t>(Min_v)}; // Enum first entry as size_t
162+
static constexpr auto Max_u_v{static_cast<size_t>(Max_v)}; // Enum last entry as size_t
163+
static constexpr bool isContinuous() noexcept { return (Max_u_v - Min_u_v + 1) == count(); } // Is the enum continuous
164+
static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value
165165

166166
template <E e>
167167
static constexpr std::string_view getName()

Common/Utils/test/testEnumFlags.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ BOOST_AUTO_TEST_CASE(Flags_test)
3434

3535
// Test default initialization
3636
EFlags flags;
37+
BOOST_TEST(flags.None == 0);
38+
BOOST_TEST(flags.All == 31);
3739
BOOST_TEST(flags.value() == 0);
3840
BOOST_TEST(!flags.any());
3941

0 commit comments

Comments
 (0)