12#if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
16#if defined(ZEROERR_ENABLE_MAGIC_ENUM) && (ZEROERR_CXX_STANDARD >= 17)
17#include "magic_enum.hpp"
20#if defined(ZEROERR_ENABLE_DSVIZ)
42template <
typename T,
typename =
void>
64 template <
typename... Args>
67 call(std::forward<Args>(args)...);
73 call(std::forward<
decltype(value)>(value));
79 auto& ss =
static_cast<std::stringstream&
>(
os);
80 ss.str(std::string());
85 template <
typename T,
typename... V>
86 void call(T value, V... others) {
88 call(std::forward<V>(others)...);
114 static std::string
type(
const T& t) {
120 print(T value,
unsigned level, const
char* lb,
rank<0>) {
os <<
tab(level) << value << lb; }
123 print(T value,
unsigned level, const
char* lb,
rank<0>) {
124 if (value ==
nullptr)
125 os <<
tab(level) <<
"nullptr" << lb;
127 os <<
tab(level) <<
"<" <<
type(value) <<
" at " << value <<
">" << lb;
132 print(T value,
unsigned level, const
char* lb,
rank<0>) {
138 print(T value,
unsigned level, const
char* lb,
rank<1>) {
139 os <<
tab(level) <<
'\'' << value <<
'\'' << lb;
142#if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
143 template <
class StructType,
unsigned... I>
144 void print_struct(
const StructType& s,
unsigned,
const char*,
detail::seq<I...>) {
145 int _[] = {(
os << (I == 0 ?
"" :
", ") << pfr::get<I>(s), 0)...};
150 print(
const T& value,
unsigned level,
const char* lb, rank<1>) {
151 os <<
tab(level) <<
"{";
153 detail::gen_seq<pfr::tuple_size<T>::value>{});
154 os <<
tab(level) <<
"}" << lb;
159 print(T value,
unsigned level, const
char* lb,
rank<2>) {
160 os <<
tab(level) << (value ?
"true" :
"false") << lb;
164 print(T value,
unsigned level, const
char* lb,
rank<2>) {
os <<
tab(level) << value << lb; }
168 print(const T& value,
unsigned level, const
char* lb,
rank<2>) {
171 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
172 if (std::next(iter) == value.end())
last =
true;
175 os <<
tab(level) <<
"}" << lb;
179 print(const T& value,
unsigned level, const
char* lb,
rank<3>) {
180 os <<
tab(level) <<
"[";
182 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
183 if (std::next(iter) == value.end())
last =
true;
186 os <<
tab(level) <<
"]" << lb;
191 print(T value,
unsigned level, const
char* lb,
rank<3>) {
192 if (value.get() ==
nullptr)
193 os <<
tab(level) <<
"nullptr" << lb;
195 os <<
tab(level) <<
"<" <<
type(value) <<
" at " << value.get() <<
">" << lb;
199 print(const T& value,
unsigned level, const
char* lb,
rank<4>) {
202 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
203 if (std::next(iter) == value.end())
last =
true;
208 os <<
tab(level) <<
"}" << lb;
212 print(T value,
unsigned level, const
char* lb,
rank<4>) {
213 os <<
tab(level) <<
"(" << value.real() <<
"+" << value.imag() <<
"i)" << lb;
217 print(T value,
unsigned level, const
char* lb,
rank<4>) {
221 template <
class TupType>
224 template <
class TupType,
unsigned... I>
226 int _[] = {(
os << (I == 0 ?
"" :
", "),
231 template <
class... Args>
232 void print(
const std::tuple<Args...>& value,
unsigned level,
const char* lb,
rank<3>) {
233 os <<
tab(level) <<
"(";
244 char* res = abi::__cxa_demangle(name, NULL, NULL, &status);
245 std::string ret = (status == 0) ? res : name;
255 throw std::runtime_error(
"Printer is not using stringstream");
256 return static_cast<std::stringstream&
>(
os).
str();
258 operator std::string()
const {
return str(); }
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition config.h:265
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition config.h:218
void_t< decltype(zeroerr::PrinterExt(std::declval< zeroerr::Printer & >(), std::declval< T & >(), 0, nullptr, zeroerr::rank< zeroerr::max_rank >()))> has_printer_ext
Definition print.h:48
void void_t
Definition typetraits.h:55
Definition benchmark.cpp:17
Printer & getStderrPrinter()
Definition print.cpp:12
void PrinterExt(Printer &, T, unsigned, const char *, rank< 0 >)
PrinterExt is an extension of Printer that allows user to write custom rules for printing.
Definition print.h:283
Printer & getStdoutPrinter()
Definition print.cpp:7
constexpr unsigned max_rank
Definition print.h:30
A functor class Printer for printing a value of any type.
Definition print.h:63
Printer()
Definition print.h:99
int indent
Definition print.h:107
bool clear_stream_before_printing
Definition print.h:111
Printer & operator()(Args &&... args)
Definition print.h:65
~Printer()
Definition print.h:100
void print(const std::tuple< Args... > &value, unsigned level, const char *lb, rank< 3 >)
Definition print.h:232
void print_tuple(const TupType &, unsigned, const char *, detail::seq<>)
Definition print.h:222
std::ostream & os
Definition print.h:109
bool isColorful
Definition print.h:104
static std::string demangle(const char *name)
Definition print.h:241
bool isQuoted
Definition print.h:106
static std::string type(const T &t)
Definition print.h:114
const char * quote()
Definition print.h:239
std::string str() const
Definition print.h:253
bool isCompact
Definition print.h:105
std::string tab(unsigned level)
Definition print.h:238
Printer & operator()(std::initializer_list< T > &&value)
Definition print.h:71
Printer(std::ostream &os)
Definition print.h:98
void call(T value)
Definition print.h:92
void check_stream()
Definition print.h:77
print(T value, unsigned level, const char *lb, rank< 0 >)
Definition print.h:120
void print_tuple(const TupType &_tup, unsigned level, const char *, detail::seq< I... >)
Definition print.h:225
bool use_stringstream
Definition print.h:110
const char * line_break
Definition print.h:108
void call(T value, V... others)
Definition print.h:86
friend std::ostream & operator<<(std::ostream &os, const Printer &P)
Definition print.h:260
Definition typetraits.h:77
has_extension is a type trait to check if user defined PrinterExt for a type
Definition print.h:43
Definition typetraits.h:74
rank is a helper class for Printer to define the priority of overloaded functions.
Definition typetraits.h:46
#define ZEROERR_IS_MAP
Definition typetraits.h:293
#define ZEROERR_IS_CONTAINER
Definition typetraits.h:279
#define ZEROERR_IS_POD
Definition typetraits.h:294
#define ZEROERR_IS_FLOAT
Definition typetraits.h:278
#define ZEROERR_IS_INT
Definition typetraits.h:277
#define ZEROERR_IS_POINTER
Definition typetraits.h:281
#define ZEROERR_IS_CLASS
Definition typetraits.h:284
#define ZEROERR_IS_STREAMABLE
Definition typetraits.h:285
#define ZEROERR_IS_CHAR
Definition typetraits.h:282
#define ZEROERR_IS_WCHAR
Definition typetraits.h:283
#define ZEROERR_IS_STRING
Definition typetraits.h:280
#define ZEROERR_IS_AUTOPTR
Definition typetraits.h:289
#define ZEROERR_IS_COMPLEX
Definition typetraits.h:287
#define ZEROERR_IS_BOOL
Definition typetraits.h:288
#define ZEROERR_ENABLE_IF(x)
Definition typetraits.h:274
#define ZEROERR_IS_ARRAY
Definition typetraits.h:286