feat(bit): add at and subscript [] access for bit class
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
|
#include "debug.h"
|
||||||
#include <version>
|
#include <version>
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
|
||||||
@ -71,6 +72,15 @@ struct Bit {
|
|||||||
return Bit<_Hi - _Lo + 1>(this->_M_data >> _Lo);
|
return Bit<_Hi - _Lo + 1>(this->_M_data >> _Lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <std::size_t _Len = 1>
|
||||||
|
constexpr auto at(target_size_t pos) const -> Bit <_Len> {
|
||||||
|
static_assert(_Len != 0, "Bit::at: _Len should be greater than 0");
|
||||||
|
debug::assert(pos + _Len <= _Nm, "Bit::at: pos out of range");
|
||||||
|
return Bit <_Len> (this->_M_data >> pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr auto operator [](target_size_t pos) const -> Bit <1> { return this->at(pos); }
|
||||||
|
|
||||||
template <std::size_t _New = kMaxLength>
|
template <std::size_t _New = kMaxLength>
|
||||||
constexpr auto zero_extend() const -> Bit<_New>;
|
constexpr auto zero_extend() const -> Bit<_New>;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user