enum utilities
More...
#include <ostream>
#include <array>
#include <ranges>
#include <type_traits>
#include <string_view>
Go to the source code of this file.
|
| #define | PENUM(NAME, ...) |
| | Create a printable enum class.
|
| |
|
| template<typename E > |
| constexpr auto | to_underlying (E e) noexcept |
| |
enum utilities
- Author
- Tim Luchterhand
- Date
- 04.10.24
◆ PENUM
| #define PENUM |
( |
|
NAME, |
|
|
|
... |
|
) |
| |
Value:enum class NAME { __VA_ARGS__ }; \
inline constexpr std::string_view __##NAME##_enum_str_vals__ = #__VA_ARGS__; \
inline constexpr std::array __##NAME##_converter__{
enum_detail::split<__##NAME##_enum_str_vals__,
','>::value };\
inline std::ostream &
operator<<(std::ostream &os, NAME e) { \
return os; \
} \
inline auto to_string(NAME e) { \
return std::string(__##NAME##_converter__.at(
to_underlying(e))); \
}
constexpr auto to_underlying(E e) noexcept
Definition enum.hpp:25
std::ostream & operator<<(std::ostream &os, Variable x)
Definition printing.cpp:11
Create a printable enum class.
specify the enum class name first and then an arbitrary number of entries.
- Parameters
-
| NAME | enum class name |
| VA_ARGS | arbitrary number of enum entries |
◆ to_underlying()
template<typename E >
| constexpr auto to_underlying |
( |
E |
e | ) |
|
|
constexprnoexcept |