lxgui
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 <string>
8 #include <type_traits>
9 #include <utility>
10 #include <variant>
11 
12 namespace lxgui::utils {
13 
15 struct empty {};
16 
25 using variant = std::variant<
26  empty,
27  bool,
28  std::int64_t,
29  std::int32_t,
30  std::int16_t,
31  std::int8_t,
32  std::uint64_t,
33  std::uint32_t,
34  std::uint16_t,
35  std::uint8_t,
36  double,
37  float,
38  std::string>;
39 
46 template<typename T>
47 T& get(variant& value) {
48  if constexpr (std::is_enum_v<T>)
49  return reinterpret_cast<T&>(std::get<std::underlying_type_t<T>>(value));
50  else
51  return std::get<T>(value);
52 }
53 
60 template<typename T>
61 const T& get(const variant& value) {
62  if constexpr (std::is_enum_v<T>)
63  return reinterpret_cast<const T&>(std::get<std::underlying_type_t<T>>(value));
64  else
65  return std::get<T>(value);
66 }
67 
68 } // namespace lxgui::utils
69 
70 #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.