repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
enum/reflect.h
Go to the documentation of this file.
1#pragma once
2#include <type_traits>
3#include <string_view>
4
6
7#if USING(REPR_USE_MAGIC_ENUM)
8 #if __has_include(<magic_enum.hpp>)
9 // include name used when pulling in magic_enum through conan
10 #include <magic_enum.hpp>
11 #elif __has_include(<magic_enum/magic_enum.hpp>)
12 // compiler explorer uses this include name
13 #include <magic_enum/magic_enum.hpp>
14 #else
15 #error "Configured to use magic_enum but could not find magic_enum"
16 #endif
17#else
18 #include "search.h"
19#endif
20
21namespace librepr {
22
23 template <typename T>
24 requires std::is_enum_v<T>
25 [[nodiscard]] constexpr auto enum_names() noexcept{
26#if USING(REPR_USE_MAGIC_ENUM)
27 return magic_enum::enum_names<T>();
28#else
30#endif
31 }
32
33 template <typename T>
34 requires std::is_enum_v<T>
35 [[nodiscard]] constexpr auto enum_name(T value) noexcept{
36#if USING(REPR_USE_MAGIC_ENUM)
37 return magic_enum::enum_name(value);
38#else
39 return ctei::dump_enum<T>::get_name(value);
40#endif
41 }
42
43 template <auto V>
44 requires std::is_enum_v<decltype(V)>
45 [[nodiscard]] constexpr std::string_view enum_name() noexcept{
46#if USING(REPR_USE_MAGIC_ENUM)
47 return magic_enum::enum_name<V>();
48#else
49 // TODO
50 return ctei::enum_name<decltype(V), V>.data();
51#endif
52 }
53
54}
T is_enum_v
decltype(Search< T >::search()) dump_enum
Definition search.h:266
constexpr auto enum_name
Definition enum/util.h:65
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
constexpr std::string_view enum_name() noexcept
Definition enum/reflect.h:45
constexpr auto enum_names() noexcept
Definition enum/reflect.h:25