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)
59 template <
typename T,
typename =
void>
81 template <
typename... Args>
84 call(std::forward<Args>(args)...);
90 call(std::forward<decltype(value)>(value));
96 auto& ss =
static_cast<std::stringstream&
>(
os);
97 ss.str(std::string());
102 template <
typename T,
typename... V>
103 void call(T value, V... others) {
105 call(std::forward<V>(others)...);
108 template <
typename T>
131 static std::string
type(
const T& t) {
137 print(T value,
unsigned level, const
char* lb,
rank<0>) {
os <<
tab(level) << value << lb; }
140 print(T value,
unsigned level, const
char* lb,
rank<0>) {
141 if (value ==
nullptr)
142 os <<
tab(level) <<
"nullptr" << lb;
144 os <<
tab(level) <<
"<" <<
type(value) <<
" at " << value <<
">" << lb;
149 print(T value,
unsigned level, const
char* lb,
rank<0>) {
155 print(T value,
unsigned level, const
char* lb,
rank<1>) {
156 os <<
tab(level) <<
'\'' << value <<
'\'' << lb;
159 #if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
160 template <
class StructType,
unsigned... I>
161 void print_struct(
const StructType& s,
unsigned,
const char*,
detail::seq<I...>) {
162 int _[] = {(
os << (I == 0 ?
"" :
", ") << pfr::get<I>(s), 0)...};
167 print(
const T& value,
unsigned level,
const char* lb, rank<1>) {
168 os <<
tab(level) <<
"{";
170 detail::gen_seq<pfr::tuple_size<T>::value>{});
171 os <<
tab(level) <<
"}" << lb;
176 print(T value,
unsigned level, const
char* lb,
rank<2>) {
177 os <<
tab(level) << (value ?
"true" :
"false") << lb;
181 print(T value,
unsigned level, const
char* lb,
rank<2>) {
os <<
tab(level) << value << lb; }
185 print(const T& value,
unsigned level, const
char* lb,
rank<2>) {
188 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
189 if (std::next(iter) == value.end())
last =
true;
192 os <<
tab(level) <<
"}" << lb;
196 print(const T& value,
unsigned level, const
char* lb,
rank<3>) {
197 os <<
tab(level) <<
"[";
199 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
200 if (std::next(iter) == value.end())
last =
true;
203 os <<
tab(level) <<
"]" << lb;
208 print(T value,
unsigned level, const
char* lb,
rank<3>) {
209 if (value.get() ==
nullptr)
210 os <<
tab(level) <<
"nullptr" << lb;
212 os <<
tab(level) <<
"<" <<
type(value) <<
" at " << value.get() <<
">" << lb;
216 print(const T& value,
unsigned level, const
char* lb,
rank<4>) {
219 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
220 if (std::next(iter) == value.end())
last =
true;
225 os <<
tab(level) <<
"}" << lb;
229 print(T value,
unsigned level, const
char* lb,
rank<4>) {
230 os <<
tab(level) <<
"(" << value.real() <<
"+" << value.imag() <<
"i)" << lb;
234 print(T value,
unsigned level, const
char* lb,
rank<4>) {
238 template <
class TupType>
241 template <
class TupType,
unsigned... I>
243 int _[] = {(
os << (I == 0 ?
"" :
", "),
248 template <
class... Args>
249 void print(
const std::tuple<Args...>& value,
unsigned level,
const char* lb,
rank<3>) {
250 os <<
tab(level) <<
"(";
261 char* res = abi::__cxa_demangle(name, NULL, NULL, &status);
262 std::string ret = (status == 0) ? res : name;
272 throw std::runtime_error(
"Printer is not using stringstream");
273 return static_cast<std::stringstream&
>(
os).
str();
275 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:65
void void_t
Definition: typetraits.h:36
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:300
Printer & getStdoutPrinter()
Definition: print.cpp:7
constexpr unsigned max_rank
Definition: print.h:47
A functor class Printer for printing a value of any type.
Definition: print.h:80
Printer & operator()(Args &&... args)
Definition: print.h:82
Printer()
Definition: print.h:116
int indent
Definition: print.h:124
bool clear_stream_before_printing
Definition: print.h:128
Printer & operator()(std::initializer_list< T > &&value)
Definition: print.h:88
~Printer()
Definition: print.h:117
void print(const std::tuple< Args... > &value, unsigned level, const char *lb, rank< 3 >)
Definition: print.h:249
void print_tuple(const TupType &, unsigned, const char *, detail::seq<>)
Definition: print.h:239
std::ostream & os
Definition: print.h:126
bool isColorful
Definition: print.h:121
static std::string demangle(const char *name)
Definition: print.h:258
bool isQuoted
Definition: print.h:123
const char * quote()
Definition: print.h:256
static std::string type(const T &t)
Definition: print.h:131
std::string str() const
Definition: print.h:270
bool isCompact
Definition: print.h:122
std::string tab(unsigned level)
Definition: print.h:255
Printer(std::ostream &os)
Definition: print.h:115
void call(T value)
Definition: print.h:109
void check_stream()
Definition: print.h:94
print(T value, unsigned level, const char *lb, rank< 0 >)
Definition: print.h:137
void print_tuple(const TupType &_tup, unsigned level, const char *, detail::seq< I... >)
Definition: print.h:242
bool use_stringstream
Definition: print.h:127
friend std::ostream & operator<<(std::ostream &os, const Printer &P)
Definition: print.h:277
const char * line_break
Definition: print.h:125
void call(T value, V... others)
Definition: print.h:103
Definition: typetraits.h:58
has_extension is a type trait to check if user defined PrinterExt for a type
Definition: print.h:60
Definition: typetraits.h:55
rank is a helper class for Printer to define the priority of overloaded functions.
Definition: print.h:44
#define ZEROERR_IS_MAP
Definition: typetraits.h:258
#define ZEROERR_IS_CONTAINER
Definition: typetraits.h:244
#define ZEROERR_IS_POD
Definition: typetraits.h:259
#define ZEROERR_IS_FLOAT
Definition: typetraits.h:243
#define ZEROERR_IS_INT
Definition: typetraits.h:242
#define ZEROERR_IS_POINTER
Definition: typetraits.h:246
#define ZEROERR_IS_CLASS
Definition: typetraits.h:249
#define ZEROERR_IS_STREAMABLE
Definition: typetraits.h:250
#define ZEROERR_IS_CHAR
Definition: typetraits.h:247
#define ZEROERR_IS_WCHAR
Definition: typetraits.h:248
#define ZEROERR_IS_STRING
Definition: typetraits.h:245
#define ZEROERR_IS_AUTOPTR
Definition: typetraits.h:254
#define ZEROERR_IS_COMPLEX
Definition: typetraits.h:252
#define ZEROERR_IS_BOOL
Definition: typetraits.h:253
#define ZEROERR_ENABLE_IF(x)
Definition: typetraits.h:239
#define ZEROERR_IS_ARRAY
Definition: typetraits.h:251