Go to the documentation of this file.
9 #ifndef EAGINE_ENUM_MAP_HPP
10 #define EAGINE_ENUM_MAP_HPP
15 #include <type_traits>
19 template <
typename Enum,
template <Enum>
class Unit, Enum Key>
20 struct static_enum_map_unit : Unit<Key> {
22 template <
typename Visitor>
23 auto _accept(Enum key, Visitor& visitor) ->
bool {
25 visitor(Key, *
static_cast<Unit<Key>*
>(
this));
31 template <
typename Visitor>
32 auto _accept(Enum key, Visitor& visitor)
const ->
bool {
34 visitor(Key, *
static_cast<const Unit<Key>*
>(
this));
40 template <
typename Visitor>
41 auto _accept(bitfield<Enum> keys, Visitor& visitor) ->
span_size_t {
43 visitor(Key, *
static_cast<Unit<Key>*
>(
this));
49 template <
typename Visitor>
50 auto _accept(bitfield<Enum> keys, Visitor& visitor)
const ->
span_size_t {
52 visitor(Key, *
static_cast<const Unit<Key>*
>(
this));
58 template <
typename Visitor>
59 auto _accept(Visitor& visitor) ->
bool {
60 visitor(Key, *
static_cast<Unit<Key>*
>(
this));
64 template <
typename Visitor>
65 auto _accept(Visitor& visitor)
const ->
bool {
66 visitor(Key, *
static_cast<const Unit<Key>*
>(
this));
73 template <
typename Enum,
template <Enum>
class Unit, Enum... Keys>
83 typename = std::enable_if_t<(
sizeof...(Args) > 1)>>
85 : static_enum_map_unit<Enum, Unit, Keys>{args...}... {}
90 auto get() noexcept -> Unit<Key>& {
97 auto get() const noexcept -> const Unit<Key>& {
104 template <
typename Visitor>
105 auto visit(Enum key, Visitor visitor) noexcept ->
bool {
106 return (
false || ... || _base<Keys>()._accept(key, visitor));
112 template <
typename Visitor>
113 auto visit(Enum key, Visitor visitor)
const noexcept ->
bool {
114 return (
false || ... || _base<Keys>()._accept(key, visitor));
120 template <
typename Visitor>
122 return (0 + ... + _base<Keys>()._accept(keys, visitor));
128 template <
typename Visitor>
131 return (0 + ... + _base<Keys>()._accept(keys, visitor));
136 template <
typename Visitor>
138 return (
true && ... && _base<Keys>()._accept(visitor));
143 template <
typename Visitor>
144 auto visit_all(Visitor visitor)
const noexcept ->
bool {
145 return (
true && ... && _base<Keys>()._accept(visitor));
150 auto _base() noexcept -> static_enum_map_unit<Enum, Unit, Key>& {
155 auto _base() const noexcept
156 -> const static_enum_map_unit<Enum, Unit, Key>& {
163 #endif // EAGINE_ENUM_MAP_HPP
auto get() const noexcept -> const Unit< Key > &
Returns a const reference to the unit with the specified enumerator key.
Definition: enum_map.hpp:97
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static_enum_map()=default
Default constructor.
Common code is placed in this namespace.
Definition: eagine.hpp:21
Class for manipulating and testing a group of enumeration-based bits.
Definition: bitfield.hpp:19
Template used to construct tag-types used mostly in tag-dispatching.
Definition: selector.hpp:21
auto visit(bitfield< Enum > keys, Visitor visitor) noexcept -> span_size_t
Calls a visitor function on the unit with the specified keys.
Definition: enum_map.hpp:121
static_enum_map(construct_from_t, const Args &... args)
Explicit construction from arguments that are passed to the units.
Definition: enum_map.hpp:84
auto visit_all(Visitor visitor) const noexcept -> bool
Calls a visitor function on all units.
Definition: enum_map.hpp:144
Class mapping from an enumerator of an instantiation of a template.
Definition: enum_map.hpp:74
auto visit_all(Visitor visitor) noexcept -> bool
Calls a visitor function on all units.
Definition: enum_map.hpp:137
auto visit(Enum key, Visitor visitor) const noexcept -> bool
Calls a visitor function on the unit with the specified key.
Definition: enum_map.hpp:113
auto get() noexcept -> Unit< Key > &
Returns a reference to the unit with the specified enumerator key.
Definition: enum_map.hpp:90
auto visit(Enum key, Visitor visitor) noexcept -> bool
Calls a visitor function on the unit with the specified key.
Definition: enum_map.hpp:105
auto visit(bitfield< Enum > keys, Visitor visitor) const noexcept -> span_size_t
Calls a visitor function on the unit with the specified keys.
Definition: enum_map.hpp:129