19#ifndef LIB_STRINGIFY_H_
20#define LIB_STRINGIFY_H_
33 virtual void dbprint(std::ostream &out)
const = 0;
40template <
class,
class =
void>
45 std::void_t<decltype(std::declval<T>().dbprint(std::declval<std::ostream &>()))>>
55template <
class,
class =
void>
59struct has_toString<T,
std::void_t<decltype(std::declval<T>().toString())>> : std::true_type {};
64template <typename T, typename = decltype(std::to_string(std::declval<T>()))>
66 return std::to_string(value);
70auto toString(
const T &value) ->
typename std::enable_if_t<has_toString_v<T>,
cstring> {
71 return value.toString();
75auto toString(T &value) ->
typename std::enable_if_t<has_toString_v<T>,
cstring> {
76 return value.toString();
80auto toString(
const T *value) ->
typename std::enable_if_t<has_toString_v<T>,
cstring> {
81 return value->toString();
85auto toString(T *value) ->
typename std::enable_if_t<has_toString_v<T>,
cstring> {
86 return value->toString();
90cstring toString(
const std::string &value);
91cstring toString(
const char *value);
93cstring toString(std::string_view value);
95cstring toString(
const big_int &value,
unsigned width,
bool sign,
unsigned int base = 10);
96cstring toString(
const void *value);
98char DigitToChar(
int digit);
102auto operator<<(std::ostream &out,
const T &value)
103 -> std::enable_if_t<Util::has_toString_v<T> && !has_dbprint_v<T>, std::ostream &> {
104 return out << value.toString();
108auto operator<<(std::ostream &out,
const T *value)
109 -> std::enable_if_t<Util::has_toString_v<T> && !has_dbprint_v<T>, std::ostream &> {
110 if (value ==
nullptr)
113 out << value->toString();
120inline auto operator<<(std::ostream &out,
121 const T &obj) -> std::enable_if_t<has_dbprint_v<T>, std::ostream &> {
127inline auto operator<<(std::ostream &out,
128 const T *obj) -> std::enable_if_t<has_dbprint_v<T>, std::ostream &> {
Definition stringify.h:31
SFINAE helper to check if given class has a toString method.
Definition stringify.h:56
Definition stringify.h:41