repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
repr/enum.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <type_traits>
4
5#include <librepr/feature.h>
8
9#if USING(REPR_USE_MAGIC_ENUM)
10#include <librepr/name/type.h>
11#endif
12
13
14namespace librepr {
15template <typename T>
16 requires std::is_enum_v<T>
17std::string repr(T const& obj) {
18 auto name = librepr::enum_name(obj);
19
20 // TODO handle compound flags
21 if (!name.empty()) {
22#if USING(REPR_USE_MAGIC_ENUM)
23 if constexpr (detail::is_scoped_enum<T>) {
24 return librepr::get_name<T>() + "::" + std::string{name};
25 }
26#endif
27 return std::string{name};
28 }
29
30 return librepr::repr(static_cast<std::underlying_type_t<T>>(obj));
31}
32} // namespace librepr
Definition concepts.h:21
Definition ctvi/ctvi.h:9
std::string repr(T const &obj)
Definition repr/enum.h:17
std::string code_for()
Definition repr:39
constexpr std::string_view enum_name() noexcept
Definition enum/reflect.h:45
constexpr ::librepr::ReprWrapper repr
Definition repr:59