SAT Solver Template
Loading...
Searching...
No Matches
Classes | Macros | Functions
enum.hpp File Reference

enum utilities More...

#include <ostream>
#include <array>
#include <ranges>
#include <type_traits>
#include <string_view>
Include dependency graph for enum.hpp:

Go to the source code of this file.

Classes

class  enum_detail::split< String, Delim >
 

Macros

#define PENUM(NAME, ...)
 Create a printable enum class.
 

Functions

template<typename E >
constexpr auto to_underlying (E e) noexcept
 

Detailed Description

enum utilities

Author
Tim Luchterhand
Date
04.10.24

Macro Definition Documentation

◆ 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) { \
os << __##NAME##_converter__.at(to_underlying(e)); \
return os; \
} \
inline auto to_string(NAME e) { \
return std::string(__##NAME##_converter__.at(to_underlying(e))); \
}
Definition enum.hpp:31
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
NAMEenum class name
VA_ARGSarbitrary number of enum entries

Function Documentation

◆ to_underlying()

template<typename E >
constexpr auto to_underlying ( e)
constexprnoexcept

Converts enum to underlying type

Template Parameters
Eenum type
Parameters
eenum to convert
Returns
value of underlying type
Note
replace with std impl in c++23: https://en.cppreference.com/w/cpp/utility/to_underlying