diff --git a/docs/bitset.adoc b/docs/bitset.adoc index 7a96248..8a79a48 100644 --- a/docs/bitset.adoc +++ b/docs/bitset.adoc @@ -22,6 +22,8 @@ platform. * `size` does the same as `count()`: `capacity()` is the static size * `empty` (size == 0) is provided * `clear` does the same as `reset` +* The single-argument constructor (from `std::uint64_t`) is `explicit`. There is + also an assignment operator from `std::uint64_t`. A bitset has two template parameters: the size of the bitset and the storage element type to use. The storage element type must be unsigned. diff --git a/include/stdx/bitset.hpp b/include/stdx/bitset.hpp index 1f780e2..34c8acd 100644 --- a/include/stdx/bitset.hpp +++ b/include/stdx/bitset.hpp @@ -170,6 +170,11 @@ class bitset { } } + constexpr auto operator=(std::uint64_t value) -> bitset & { + *this = bitset{value}; + return *this; + } + template constexpr explicit bitset(place_bits_t, Bs... bs) { static_assert(((std::is_integral_v or std::is_enum_v) and ...), diff --git a/test/bitset.cpp b/test/bitset.cpp index 9864606..2191bd2 100644 --- a/test/bitset.cpp +++ b/test/bitset.cpp @@ -575,3 +575,9 @@ TEST_CASE("fix type of bitset argument to std::size_t", "[bitset]") { STATIC_CHECK(std::same_as); STATIC_CHECK(std::same_as>); } + +TEST_CASE("bitset assign", "[bitset]") { + auto bs = stdx::bitset<16>{}; + bs = 0xa5a5; + CHECK(bs.to_natural() == 0xa5a5); +}