EnTT 3.14.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>
21struct monostate {
28 template<typename Type>
29 monostate &operator=(Type val) noexcept {
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)
57
58} // namespace entt
59
60#endif
EnTT default namespace.
Definition dense_map.hpp:22
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:219
monostate< Value > monostate_v
Helper variable template.
Definition monostate.hpp:56
Minimal implementation of the monostate pattern.
Definition monostate.hpp:21
monostate & operator=(Type val) noexcept
Assigns a value of a specific type to a given key.
Definition monostate.hpp:29