EnTT: src/entt/core/monostate.hpp Source File

EnTT 3.16.0

Loading...
Searching...
No Matches
monostate.hpp
1#ifndef ENTT_CORE_MONOSTATE_HPP
2#define ENTT_CORE_MONOSTATE_HPP
3
4#include "../config/config.h"
5#include "fwd.hpp"
6
7namespace entt {
8
20template<id_type>
21 struct monostate {
28 template<typename Type>
29 monostate &operator=(Type val) noexcept {
30 value<Type> = val;
31 return *this;
32 }
33
39 template<typename Type>
40 operator Type() const noexcept {
41 return value<Type>;
42 }
43
44private:
45 template<typename Type>
46 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
47 inline static ENTT_MAYBE_ATOMIC(Type) value{};
48};
49
54template<id_type Value>
55// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
56 inline monostate<Value> monostate_v{};
57
58} // namespace entt
59
60#endif
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::monostate_v
monostate< Value > monostate_v
Helper variable template.
Definition monostate.hpp:56
entt::monostate
Minimal implementation of the monostate pattern.
Definition monostate.hpp:21
entt::monostate::operator=
monostate & operator=(Type val) noexcept
Assigns a value of a specific type to a given key.
Definition monostate.hpp:29