Skip to content

Commit f27dfd9

Browse files
Peter-McLean-AlteraPeterCDMcLean
authored andcommitted
span constructor from bit range
1 parent 6dd01e0 commit f27dfd9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

include/bitlib/bit-containers/bit_span.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "bitlib/bit-algorithms/bit_algorithm.hpp"
1414
#include "bitlib/bit-containers/bit_bitsof.hpp"
1515
#include "bitlib/bit-iterator/bit.hpp"
16+
#include "bitlib/bit_concepts.hpp"
1617

1718
namespace bit {
1819

@@ -88,6 +89,8 @@ class bit_span : private bit_span_storage<WordType, Extent> {
8889
constexpr bit_span(WordType* s)
8990
requires(std::is_scalar_v<WordType>);
9091

92+
constexpr bit_span(bit_range auto& other);
93+
9194
// --- Observers ---
9295

9396
// Returns the number of bits in the span.
@@ -215,6 +218,16 @@ constexpr bit_span<WordType, Extent>::bit_span(WordType& word_ref)
215218
: bit_span(&word_ref) {
216219
}
217220

221+
template <typename WordType, std::size_t Extent>
222+
constexpr bit_span<WordType, Extent>::bit_span(bit_range auto& other) {
223+
if constexpr (Extent == std::dynamic_extent) {
224+
this->size_ = other.size();
225+
} else {
226+
assert(other.size() == Extent);
227+
}
228+
this->data_ = &(*other.begin());
229+
}
230+
218231
// --- Observers ---
219232

220233
// Returns the number of bits in the span.

0 commit comments

Comments
 (0)