teslamotors / fixed-containers

C++ Fixed Containers
MIT License
395 stars 38 forks source link

[SkeletalRichEnum] Fix ordinal() and value_of(underlying_int) #70

Closed alexkaratarakis closed 1 year ago

alexkaratarakis commented 1 year ago
enum class TestRichEnum1BackingEnum : std::uint32_t
{
    C_ONE = 19,
    C_FOUR = 25,
    C_TWO = 21,
    C_THREE = 23,
};

static_assert(TestRichEnum1::C_ONE().ordinal() == 0);
static_assert(TestRichEnum1::C_TWO().ordinal() == 1);
static_assert(TestRichEnum1::C_THREE().ordinal() == 2);
static_assert(TestRichEnum1::C_FOUR().ordinal() == 3);

static_assert(TestRichEnum1::value_of(19) == TestRichEnum1::C_ONE());
static_assert(TestRichEnum1::value_of(21) == TestRichEnum1::C_TWO());
static_assert(TestRichEnum1::value_of(23) == TestRichEnum1::C_THREE());
static_assert(TestRichEnum1::value_of(25) == TestRichEnum1::C_FOUR());
static_assert(TestRichEnum1::value_of(29) == std::nullopt);