Stax
Programming language
Loading...
Searching...
No Matches
reflect.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/describe.hpp>
4#include <boost/type_index.hpp>
5#include <string>
6
7namespace stax::reflect {
8
9constexpr auto Unqualified(std::string sv) {
10 if (sv.find(':') == std::string::npos) return sv;
11 return sv.substr(sv.find_last_of(':') + 1);
12}
13
14template <typename T>
15constexpr auto GetTypeName() -> std::string {
16 auto tidx = boost::typeindex::type_id<T>().pretty_name();
17 return Unqualified(tidx);
18}
19
20template <typename T>
21constexpr auto GetTypeName(const T&) -> std::string {
22 auto tidx = boost::typeindex::type_id<T>().pretty_name();
23 return Unqualified(tidx);
24}
25
26template <typename T>
27constexpr auto GetAllFieldNames() {
28 constexpr size_t kFieldCount = boost::mp11::mp_size<
29 boost::describe::describe_members<T, boost::describe::mod_any_access>>();
30 std::array<std::string, kFieldCount> names;
31
32 size_t i = 0;
33 boost::mp11::mp_for_each<
34 boost::describe::describe_members<T, boost::describe::mod_any_access>>(
35 [&i, &names](const auto& member) { names.at(i++) = member.name; });
36
37 return names;
38}
39
40} // namespace stax::reflect
Definition reflect.hpp:7
constexpr auto GetAllFieldNames()
Definition reflect.hpp:27
constexpr auto Unqualified(std::string sv)
Definition reflect.hpp:9
constexpr auto GetTypeName() -> std::string
Definition reflect.hpp:15