6#pragma push_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
7#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
8#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
20#include <initializer_list>
23#if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
27#if defined(ZEROERR_ENABLE_MAGIC_ENUM) && (ZEROERR_CXX_STANDARD >= 17)
28#include "magic_enum.hpp"
31#if defined(ZEROERR_ENABLE_DSVIZ)
53template <
typename T,
typename =
void>
64#if defined(ZEROERR_ENABLE_PFR) && ZEROERR_CXX_STANDARD >= 14 && !PFR_USE_CPP17 && !PFR_USE_LOOPHOLE
67template <class T, bool = std::is_class<T>::value && std::is_trivial<T>::value &&
68 std::is_standard_layout<T>::value>
69struct is_classic_pfr_printable : std::false_type {};
72struct is_classic_pfr_printable<T, true>
73 : std::integral_constant<bool, pfr::detail::is_flat_refelectable<T>(
74 pfr::detail::make_index_sequence<pfr::detail::fields_count<T>()>{})> {};
88 template <
typename... Args>
91 call(std::forward<Args>(args)...);
97 call(std::forward<
decltype(value)>(value));
105 template <
typename T,
typename... V>
106 void call(T&& value, V&&... others) {
108 call(std::forward<V>(others)...);
111 template <
typename T>
122 template <
class Stream>
123 explicit Printer(Stream& stream) :
os(storage_) { storage_.attach(stream); }
140 return demangle(
typeid(t).name());
143#if defined(ZEROERR_ENABLE_MAGIC_ENUM) && (ZEROERR_CXX_STANDARD >= 17)
154 os << tab(
level) <<
"<unprintable enum " <<
type(value) <<
">" <<
lb;
162 !std::is_function<
typename std::remove_pointer<T>::type>::value)
164 if (value ==
nullptr)
167 os << tab(
level) <<
"<" <<
type(value) <<
" at " <<
static_cast<const void*
>(value) <<
">" <<
lb;
171 std::is_function<
typename std::remove_pointer<T>::type>::value)
173 if (value ==
nullptr)
177 <<
reinterpret_cast<const void*
>(value) <<
">" <<
lb;
180 template <
class R,
class... Args>
181 void print(
const std::function<R(Args...)>& value,
unsigned level,
const char*
lb, rank<3>) {
185 os << tab(
level) <<
"<" <<
type(value) <<
" holding "
186 << demangle(value.target_type().name()) <<
">" <<
lb;
192 template <
typename T, std::
size_t N>
204 print(
const T& value,
unsigned level,
const char*
lb, rank<1>) {
205 os << tab(
level) <<
'\'' << value <<
'\'' <<
lb;
208#if defined(ZEROERR_ENABLE_PFR) && (ZEROERR_CXX_STANDARD >= 14)
209 template <
class StructType,
unsigned... I>
210 void print_struct(
const StructType& s,
unsigned,
const char*, detail::seq<I...>) {
211 int _[] = {(
os << (I == 0 ?
"" :
", ") << pfr::get<I>(s), 0)...};
215#if PFR_USE_CPP17 || PFR_USE_LOOPHOLE
220 print(
const T& value,
unsigned level,
const char*
lb, rank<1>) {
223 detail::gen_seq<pfr::tuple_size<T>::value>{});
229 print(
const T& value,
unsigned level,
const char*
lb, rank<2>) {
230 os << tab(
level) << (value ?
"true" :
"false") <<
lb;
238 print(
const T& value,
unsigned level,
const char*
lb, rank<2>) {
241 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
244 if (next == value.end())
last =
true;
251 print(
const T& value,
unsigned level,
const char*
lb, rank<3>) {
254 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
257 if (next == value.end())
last =
true;
258 print(*iter, 0,
last ?
"" :
", ", rank<max_rank>{});
265 print(
const T& value,
unsigned level,
const char*
lb, rank<3>) {
266 if (value.get() ==
nullptr)
269 os << tab(
level) <<
"<" <<
type(value) <<
" at " <<
static_cast<const void*
>(value.get()) <<
">" <<
lb;
274 print(
const T& value,
unsigned level,
const char*
lb, rank<4>) {
277 for (
auto iter = value.begin(); iter != value.end(); ++iter) {
280 if (next == value.end())
last =
true;
281 print((*iter).first,
level + 1,
" : ", rank<max_rank>{});
289 print(
const T& value,
unsigned level,
const char*
lb, rank<4>) {
290 const auto locked = value.lock();
295 print(
const T& value,
unsigned level,
const char*
lb, rank<4>) {
296 os << tab(
level) <<
"(" << value.real() <<
"+" << value.imag() <<
"i)" <<
lb;
300 print(
const T& value,
unsigned level,
const char*
lb, rank<4>) {
302 write_string(value,
typename detail::is_string_like<T>::type{});
307 void write_string(
const T& value, std::true_type) {
308 if (value.size() != 0)
309 os.write(value.data(),
static_cast<std::size_t
>(value.size()));
312 void write_string(
const T& value, std::false_type) {
313 const char* text = value;
314 os << (text ? text :
"nullptr");
317 template <
class TupType>
318 inline void print_tuple(
const TupType&,
unsigned,
const char*, detail::seq<>) {}
320 template <
class TupType,
unsigned... I>
321 inline void print_tuple(
const TupType& _tup,
unsigned level,
const char*, detail::seq<I...>) {
322 int _[] = {(
os << (I == 0 ?
"" :
", "),
328 print(
const T& value,
unsigned level,
const char*
lb, rank<3>) {
334 void print_text(
const char* value) {
os << value; }
335 template <
class T>
void print_text(
const T& value) {
os.write(value.data(), value.size()); }
336 zeroerr::String tab(
unsigned level);
337 const char* quote() {
return isQuoted ?
"\"" :
""; }
339 static zeroerr::String demangle(
const char* name);
341 zeroerr::String str()
const;
342 operator zeroerr::String()
const {
return str(); }
343 template <class T, typename std::enable_if<detail::StringLike<T>::owning &&
344 !std::is_same<T, String>::value,
int>
::type = 0>
345 operator T()
const {
return str(); }
360 printer.
call(*
static_cast<T*
>(
const_cast<void*
>(value)));
365 return {
const_cast<const void*
>(
static_cast<const volatile void*
>(std::addressof(value))),
400#pragma pop_macro("_LIBCPP_REMOVE_TRANSITIVE_INCLUDES")
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition config.h:283
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition config.h:235
Definition assert_text.cpp:6
auto tuple_get(T &&value) -> decltype(get< I >(std::forward< T >(value)))
Definition typetraits.h:182
void void_t
Definition typetraits.h:55
void printDiagnosticValue(Printer &printer, const void *value)
Definition print.h:359
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:57
DiagnosticValue makeDiagnosticValue(T &value)
Definition print.h:364
Definition assert_text.cpp:5
StringBuffer & operator<<(StringBuffer &buffer, const Printer &printer)
Definition print.h:349
Printer & getStderrPrinter()
Definition print.cpp:14
void PrinterExt(Printer &, const T &, unsigned, const char *, rank< 0 >)
PrinterExt is an extension of Printer that allows user to write custom rules for printing.
Definition print.h:388
Printer & getStdoutPrinter()
Definition print.cpp:9
constexpr unsigned max_rank
Definition print.h:41
A functor class Printer for printing a value of any type.
Definition print.h:87
Printer()
Definition print.h:121
int indent
Definition print.h:132
print(const T &value, unsigned level, const char *lb, rank< 0 >)
Definition print.h:148
bool clear_stream_before_printing
Definition print.h:136
unsigned const char * lb
Definition print.h:163
Printer & operator()(Args &&... args)
Definition print.h:89
Printer(const Printer &other)
Definition print.h:124
StringBuffer & os
Definition print.h:134
bool isColorful
Definition print.h:129
unsigned const char rank< 0 >
Definition print.h:163
bool isQuoted
Definition print.h:131
void call(T &&value, V &&... others)
Definition print.h:106
static zeroerr::String type(const T &t)
Definition print.h:139
bool isCompact
Definition print.h:130
Printer(Stream &stream)
Definition print.h:123
Printer & operator()(std::initializer_list< T > &&value)
Definition print.h:95
void call(T &&value)
Definition print.h:112
void check_stream()
Definition print.h:101
ZEROERR_ENABLE_IF(ZEROERR_IS_POINTER &&!std::is_function< typename std::remove_pointer< T >::type >::value) print(const T &value
bool use_stringstream
Definition print.h:135
const char * line_break
Definition print.h:133
unsigned level
Definition print.h:163
has_extension is a type trait to check if user defined PrinterExt for a type
Definition print.h:54
Definition typetraits.h:97
rank is a helper class for Printer to define the priority of overloaded functions.
Definition typetraits.h:43
#define last
Definition table.cpp:255
#define ZEROERR_IS_MAP
Definition typetraits.h:351
#define ZEROERR_IS_ENUM
Definition typetraits.h:339
#define ZEROERR_IS_CONTAINER
Definition typetraits.h:340
#define ZEROERR_IS_POD
Definition typetraits.h:352
#define ZEROERR_IS_FLOAT
Definition typetraits.h:338
#define ZEROERR_IS_INT
Definition typetraits.h:337
#define ZEROERR_IS_POINTER
Definition typetraits.h:342
#define ZEROERR_IS_CLASS
Definition typetraits.h:345
#define ZEROERR_IS_STREAMABLE
Definition typetraits.h:346
#define ZEROERR_IS_CHAR
Definition typetraits.h:343
#define ZEROERR_IS_WCHAR
Definition typetraits.h:344
#define ZEROERR_IS_STRING
Definition typetraits.h:341
#define ZEROERR_IS_AUTOPTR
Definition typetraits.h:350
#define ZEROERR_IS_COMPLEX
Definition typetraits.h:348
#define ZEROERR_IS_BOOL
Definition typetraits.h:349
#define ZEROERR_ENABLE_IF(x)
Definition typetraits.h:334
#define ZEROERR_IS_ARRAY
Definition typetraits.h:347