Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Common/Utils/include/CommonUtils/EnumFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ struct FlagsHelper final {
static constexpr auto Max_v{Values.back()}; // Enum last entry
static constexpr auto Min_u_v{static_cast<size_t>(Min_v)}; // Enum first entry as size_t
static constexpr auto Max_u_v{static_cast<size_t>(Max_v)}; // Enum last entry as size_t
static constexpr bool isContinuous() noexcept { return (Max_u_v - Min_u_v + 1) == count(); } // Is the enum continuous
static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value
static_assert(Max_u_v < std::numeric_limits<U>::digits, "Max Bit is beyond allow range defered from underlying type");
static constexpr bool isContinuous() noexcept { return (Max_u_v - Min_u_v + 1) == count(); } // Is the enum continuous
static constexpr auto MaxRep{((1ULL << (static_cast<unsigned long long>(Max_u_v - Min_u_v) + 1ULL)) - 1ULL) << Min_u_v}; // largest representable value

template <E e>
static constexpr std::string_view getName()
Expand Down
47 changes: 47 additions & 0 deletions Common/Utils/test/testEnumFlags.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,46 @@ enum class TestEnum : uint8_t {
Bit5VeryLongName,
};

// Very long enum
// to test that it works beyond 32 bits
enum class TestEnumLong : uint64_t {
Bit1,
Bit2,
Bit3,
Bit4,
Bit5,
Bit6,
Bit7,
Bit8,
Bit9,
Bit10,
Bit11,
Bit12,
Bit13,
Bit14,
Bit15,
Bit16,
Bit17,
Bit18,
Bit19,
Bit20,
Bit21,
Bit22,
Bit23,
Bit24,
Bit25,
Bit26,
Bit27,
Bit28,
Bit29,
Bit30,
Bit31,
Bit32,
Bit33,
Bit34,
// ...
};

BOOST_AUTO_TEST_CASE(Flags_test)
{
using EFlags = o2::utils::EnumFlags<TestEnum>;
Expand Down Expand Up @@ -257,4 +297,11 @@ BOOST_AUTO_TEST_CASE(Flags_test)
EFlags flags3{TestEnum::Bit4};
BOOST_CHECK(!flags1.contains(flags3)); // flags1 does not contain flags3
}

{
// Test compilation using an enum with more than 32 bits
o2::utils::EnumFlags<TestEnumLong> test;
test.set("Bit32");
BOOST_CHECK(test.test(TestEnumLong::Bit32));
}
}