Iros
 
Loading...
Searching...
No Matches
bit_struct.h
Go to the documentation of this file.
1#pragma once
2
5#include "di/meta/algorithm.h"
8
9namespace di::bit {
10template<size_t byte_size, concepts::BitTag... Tags>
11class [[gnu::packed]] BitStruct {
12 using List = meta::List<Tags...>;
13
14public:
15 BitStruct() = default;
16
17 template<concepts::BitTag... FromTags>
18 requires(meta::Contains<List, FromTags> && ...)
19 constexpr explicit BitStruct(FromTags... tags) {
20 auto arguments = di::make_tuple(tags...);
22 [&]<concepts::BitTag T>(T tag) {
23 this->template set<T>(tag.get());
24 },
25 arguments);
26 }
27
28 template<concepts::BitTag Tag>
29 constexpr void set(meta::BitValue<Tag> value) {
30 Tag::value_into_bits(m_bitset, value);
31 }
32
33 template<concepts::BitTag Tag, typename R = meta::BitValue<Tag>>
34 constexpr auto get() const -> R {
35 return Tag::bits_into_value(m_bitset);
36 }
37
38private:
39 BitSet<8 * byte_size> m_bitset;
40};
41}
42
43namespace di {
44using bit::BitStruct;
45}
Definition bit_set.h:11
constexpr auto get() const -> R
Definition bit_struct.h:34
constexpr void set(meta::BitValue< Tag > value)
Definition bit_struct.h:29
Definition bit_tag.h:17
Definition list.h:119
Definition bit_proxy_reference.h:5
T::Value BitValue
Definition bit_tag.h:12
Definition zstring_parser.h:9
constexpr auto make_tuple(Args &&... args)
Definition make_tuple.h:9
constexpr void tuple_for_each(F &&function, Tup &&tuple)
Definition tuple_for_each.h:22
Definition core.h:5