diff --git a/include/zeus/enum_bitfield.hpp b/include/zeus/enum_bitfield.hpp index 78b6457..8ce52c0 100644 --- a/include/zeus/enum_bitfield.hpp +++ b/include/zeus/enum_bitfield.hpp @@ -26,6 +26,12 @@ namespace zeus return *this; } + constexpr EnumBitfield& operator=(BaseType field) + { + m_field = field; + return *this; + } + constexpr BaseType bits() const { return m_field; diff --git a/test/enum_bitfield_test.cpp b/test/enum_bitfield_test.cpp index e5ed38f..88ccfcf 100644 --- a/test/enum_bitfield_test.cpp +++ b/test/enum_bitfield_test.cpp @@ -59,20 +59,44 @@ TEST_CASE("[EnumBitfield] - operator=", "[zeus]") { SECTION("Runtime") { - EnumBitfield a; - a = Bits::b; - REQUIRE(a.bits() == 2); + SECTION("From enum") + { + EnumBitfield a; + a = Bits::b; + REQUIRE(a.bits() == 2); + } + + SECTION("From base type") + { + EnumBitfield a; + a = 2; + REQUIRE(a.bits() == 2); + } } SECTION("Compile-time") { - static constexpr auto val = []() { - EnumBitfield a; - a = Bits::b; - return a.bits(); - }(); + SECTION("From enum") + { + static constexpr auto val = []() { + EnumBitfield a; + a = Bits::b; + return a.bits(); + }(); - STATIC_REQUIRE(val == 2); + STATIC_REQUIRE(val == 2); + } + + SECTION("From base type") + { + static constexpr auto val = []() { + EnumBitfield a; + a = 2; + return a.bits(); + }(); + + STATIC_REQUIRE(val == 2); + } } }