File: VariantAlternativeWrapper.hpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (50 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef RFL_PARSING_VARIANTALTERNATIVEWRAPPER_HPP_
#define RFL_PARSING_VARIANTALTERNATIVEWRAPPER_HPP_

#include <type_traits>

#include "../Field.hpp"
#include "../Literal.hpp"
#include "../internal/StringLiteral.hpp"
#include "../internal/get_type_name.hpp"
#include "../internal/has_tag_v.hpp"
#include "../internal/remove_namespaces.hpp"

namespace rfl::parsing {

namespace vaw {

template <class T>
struct GetName {};

template <internal::StringLiteral _name>
struct GetName<Literal<_name>> {
  constexpr static internal::StringLiteral name_ = _name;
};

template <class T, bool _remove_namespaces = true>
consteval auto make_tag() {
  if constexpr (internal::has_tag_v<T>) {
    return typename T::Tag();
  } else if constexpr (std::is_same_v<std::remove_cvref_t<T>, std::string>) {
    return Literal<"std::string">();
  } else if constexpr (_remove_namespaces) {
    return Literal<
        internal::remove_namespaces<internal::get_type_name<T>()>()>();
  } else {
    return Literal<internal::get_type_name<T>()>();
  }
}

template <class T, bool _remove_namespaces = true>
using tag_t = std::invoke_result_t<
    decltype(make_tag<std::remove_cvref_t<std::remove_pointer_t<T>>, _remove_namespaces>)>;

}  // namespace vaw

template <class T, bool _remove_namespaces = true>
using VariantAlternativeWrapper = Field<vaw::GetName<vaw::tag_t<T, _remove_namespaces>>::name_, T>;

}  // namespace rfl::parsing

#endif