lxgui
Loading...
Searching...
No Matches
utils_variant.hpp
1#ifndef LXGUI_UTILS_VARIANT_HPP
2#define LXGUI_UTILS_VARIANT_HPP
3
4#include "lxgui/lxgui.hpp"
5#include "lxgui/utils.hpp"
6
7#include <cstdint>
8#include <string>
9#include <type_traits>
10#include <utility>
11#include <variant>
12
13namespace lxgui::utils {
14
16struct empty {};
17
26using variant = std::variant<
27 empty,
28 bool,
29 std::int64_t,
30 std::int32_t,
31 std::int16_t,
32 std::int8_t,
33 std::uint64_t,
34 std::uint32_t,
35 std::uint16_t,
36 std::uint8_t,
37 double,
38 float,
39 std::string>;
40
47template<typename T>
48T& get(variant& value) {
49 if constexpr (std::is_enum_v<T>)
50 return reinterpret_cast<T&>(std::get<std::underlying_type_t<T>>(value));
51 else
52 return std::get<T>(value);
53}
54
61template<typename T>
62const T& get(const variant& value) {
63 if constexpr (std::is_enum_v<T>)
64 return reinterpret_cast<const T&>(std::get<std::underlying_type_t<T>>(value));
65 else
66 return std::get<T>(value);
67}
68
69} // namespace lxgui::utils
70
71#endif
std::variant< empty, bool, std::int64_t, std::int32_t, std::int16_t, std::int8_t, std::uint64_t, std::uint32_t, std::uint16_t, std::uint8_t, double, float, std::string > variant
Type-erased value for passing arguments to events.
T & get(variant &value)
Retrieve the value stored in an utils::variant.
Empty type, used in the implementation of utils::variant.