OGLplus  (0.59.0) a C++ wrapper for rendering APIs

map_enumerators.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_REFLECT_MAP_ENUMERATORS_HPP
10 #define EAGINE_REFLECT_MAP_ENUMERATORS_HPP
11 
12 #include "../selector.hpp"
13 #include "decl_name.hpp"
14 #include <array>
15 #include <type_traits>
16 
17 namespace eagine {
18 //------------------------------------------------------------------------------
19 template <typename T>
20 struct enumerator_and_name {
21  constexpr enumerator_and_name(decl_name n, T e) noexcept
22  : name{n}
23  , enumerator{e} {}
24 
25  const decl_name name;
26  const T enumerator;
27 };
28 //------------------------------------------------------------------------------
29 template <typename T, std::size_t N>
30 using enumerator_map_type = std::array<enumerator_and_name<T>, N>;
31 //------------------------------------------------------------------------------
32 template <typename T, typename Selector>
33 struct does_have_enumerator_mapping {
34 private:
35  template <
36  typename X,
37  typename = decltype(enumerator_mapping(type_identity<X>(), Selector()))>
38  static auto _test(X*) -> std::true_type;
39  static auto _test(...) -> std::false_type;
40 
41 public:
42  // NOLINTNEXTLINE(hicpp-vararg)
43  using type = decltype(_test(static_cast<std::remove_cv_t<T>*>(nullptr)));
44 };
45 //------------------------------------------------------------------------------
46 template <typename T, typename Selector = default_selector_t>
47 using has_enumerator_mapping_t =
48  typename does_have_enumerator_mapping<T, Selector>::type;
49 
50 template <typename T, typename Selector = default_selector_t>
51 constexpr const bool has_enumerator_mapping_v =
52  has_enumerator_mapping_t<T, Selector>::value;
53 //------------------------------------------------------------------------------
54 } // namespace eagine
55 
56 #endif // EAGINE_REFLECT_MAP_ENUMERATORS_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).