11#if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
15#if defined(ZEROERR_ENABLE_MAGIC_ENUM) && (ZEROERR_CXX_STANDARD >= 17)
16#include "magic_enum.hpp"
19#if defined(ZEROERR_ENABLE_DSVIZ)
41template <
typename T,
typename =
void>
63 template <
typename... Args>
66 call(std::forward<Args>(args)...);
72 call(std::forward<
decltype(value)>(value));
78 auto& ss =
static_cast<std::stringstream&
>(
os);
79 ss.str(std::string());
84 template <
typename T,
typename... V>
85 void call(T value, V... others) {
87 call(std::forward<V>(others)...);
113 static std::string
type(
const T& t) {
119 print(T value,
unsigned level, const
char* lb,
rank<0>) {
os <<
tab(level) << value << lb; }
122 print(T value,
unsigned level, const
char* lb,
rank<0>) {
123 if (value ==
nullptr)
124 os <<
tab(level) <<
"nullptr" << lb;
126 os <<
tab(level) <<
"<" <<
type(value) <<
" at " << value <<
">" << lb;
131 print(T value,
unsigned level, const
char* lb,
rank<0>) {
137 print(T value,
unsigned level, const
char* lb,
rank<1>) {
138 os <<
tab(level) <<
'\'' << value <<
'\'' << lb;
141#if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
142 template <
class StructType,
unsigned... I>
143 void print_struct(
const StructType& s,
unsigned,
const char*,
detail::seq<I...>) {
144 int _[] = {(
os << (I == 0 ?
"" :
", ") << pfr::get<I>(s), 0)...};
149 print(
const T& value,
unsigned level,
const char* lb, rank<1>) {
150 os <<
tab(level) <<
"{";
152 detail::gen_seq<pfr::tuple_size<T>::value>{});
153 os <<
tab(level) <<
"}" << lb;
158 print(T value,
unsigned level, const
char* lb,
rank<2>) {
159 os <<
tab(level) << (value ?
"true" :
"false") << lb;
163 print(T value,
unsigned level, const
char* lb,
rank<2>) {
os <<
tab(level) << value << lb; }
167 print(const T& value,
unsigned level, const
char* lb,
rank<2>) {
170 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
171 if (std::next(iter) == value.end())
last =
true;
174 os <<
tab(level) <<
"}" << lb;
178 print(const T& value,
unsigned level, const
char* lb,
rank<3>) {
179 os <<
tab(level) <<
"[";
181 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
182 if (std::next(iter) == value.end())
last =
true;
185 os <<
tab(level) <<
"]" << lb;
190 print(T value,
unsigned level, const
char* lb,
rank<3>) {
191 if (value.get() ==
nullptr)
192 os <<
tab(level) <<
"nullptr" << lb;
194 os <<
tab(level) <<
"<" <<
type(value) <<
" at " << value.get() <<
">" << lb;
198 print(const T& value,
unsigned level, const
char* lb,
rank<4>) {
201 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
202 if (std::next(iter) == value.end())
last =
true;
207 os <<
tab(level) <<
"}" << lb;
211 print(T value,
unsigned level, const
char* lb,
rank<4>) {
212 os <<
tab(level) <<
"(" << value.real() <<
"+" << value.imag() <<
"i)" << lb;
216 print(T value,
unsigned level, const
char* lb,
rank<4>) {
220 template <
class TupType>
223 template <
class TupType,
unsigned... I>
225 int _[] = {(
os << (I == 0 ?
"" :
", "),
230 template <
class... Args>
231 void print(
const std::tuple<Args...>& value,
unsigned level,
const char* lb,
rank<3>) {
232 os <<
tab(level) <<
"(";
243 char* res = abi::__cxa_demangle(name, NULL, NULL, &status);
244 std::string ret = (status == 0) ? res : name;
254 throw std::runtime_error(
"Printer is not using stringstream");
255 return static_cast<std::stringstream&
>(
os).
str();
257 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:47
void void_t
Definition typetraits.h:41
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:282
Printer & getStdoutPrinter()
Definition print.cpp:7
constexpr unsigned max_rank
Definition print.h:29
A functor class Printer for printing a value of any type.
Definition print.h:62
Printer()
Definition print.h:98
int indent
Definition print.h:106
bool clear_stream_before_printing
Definition print.h:110
Printer & operator()(Args &&... args)
Definition print.h:64
~Printer()
Definition print.h:99
void print(const std::tuple< Args... > &value, unsigned level, const char *lb, rank< 3 >)
Definition print.h:231
void print_tuple(const TupType &, unsigned, const char *, detail::seq<>)
Definition print.h:221
std::ostream & os
Definition print.h:108
bool isColorful
Definition print.h:103
static std::string demangle(const char *name)
Definition print.h:240
bool isQuoted
Definition print.h:105
static std::string type(const T &t)
Definition print.h:113
const char * quote()
Definition print.h:238
std::string str() const
Definition print.h:252
bool isCompact
Definition print.h:104
std::string tab(unsigned level)
Definition print.h:237
Printer & operator()(std::initializer_list< T > &&value)
Definition print.h:70
Printer(std::ostream &os)
Definition print.h:97
void call(T value)
Definition print.h:91
void check_stream()
Definition print.h:76
print(T value, unsigned level, const char *lb, rank< 0 >)
Definition print.h:119
void print_tuple(const TupType &_tup, unsigned level, const char *, detail::seq< I... >)
Definition print.h:224
bool use_stringstream
Definition print.h:109
const char * line_break
Definition print.h:107
void call(T value, V... others)
Definition print.h:85
friend std::ostream & operator<<(std::ostream &os, const Printer &P)
Definition print.h:259
Definition typetraits.h:63
has_extension is a type trait to check if user defined PrinterExt for a type
Definition print.h:42
Definition typetraits.h:60
rank is a helper class for Printer to define the priority of overloaded functions.
Definition typetraits.h:32
#define ZEROERR_IS_MAP
Definition typetraits.h:279
#define ZEROERR_IS_CONTAINER
Definition typetraits.h:265
#define ZEROERR_IS_POD
Definition typetraits.h:280
#define ZEROERR_IS_FLOAT
Definition typetraits.h:264
#define ZEROERR_IS_INT
Definition typetraits.h:263
#define ZEROERR_IS_POINTER
Definition typetraits.h:267
#define ZEROERR_IS_CLASS
Definition typetraits.h:270
#define ZEROERR_IS_STREAMABLE
Definition typetraits.h:271
#define ZEROERR_IS_CHAR
Definition typetraits.h:268
#define ZEROERR_IS_WCHAR
Definition typetraits.h:269
#define ZEROERR_IS_STRING
Definition typetraits.h:266
#define ZEROERR_IS_AUTOPTR
Definition typetraits.h:275
#define ZEROERR_IS_COMPLEX
Definition typetraits.h:273
#define ZEROERR_IS_BOOL
Definition typetraits.h:274
#define ZEROERR_ENABLE_IF(x)
Definition typetraits.h:260
#define ZEROERR_IS_ARRAY
Definition typetraits.h:272