Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <assert.h>
- #include <bitset>
- #include <cstdint>
- #include <limits>
- #include <type_traits>
- using u8 = std::uint8_t;
- using u16 = std::uint16_t;
- using u32 = std::uint32_t;
- using u64 = std::uint64_t;
- template <typename T>
- struct Register {
- T data;
- T value;
- bitset<sizeof(T) * CHAR_BIT> bits;
- Register() : data(), value() {}
- template <typename P>
- explicit Register(const P val) : data(static_cast<T>(val)), value(data), bits(data) {}
- template <typename P>
- Register(const P val, const unsigned char idx) : data(static_cast<T>((val >> std::size(bits) * idx) & numeric_limits<make_unsigned_t<T>>::max())), value(data), bits(data) {
- assert(idx == '