56 std::string
tiname(
const std::type_info &ti)
60#elif defined(__GNUG__)
62 std::unique_ptr<char, void (*)(
void *)> result(
63 abi::__cxa_demangle(ti.name(),
nullptr,
nullptr, &status),
65 return (status == 0) ? result.get() : ti.name();
71#ifndef CONSOLE_PLAIN_REPR
81 os <<
'"' << value <<
'"';
93 os <<
"'" << value <<
"'";
103 typename std::enable_if<
104 std::is_same<typename std::decay<T>::type,
bool>::value>::type
105 repr(
T &&value, std::ostream &os = std::cout)
107 os << (value ?
"true" :
"false");
117 typename std::enable_if<
118 std::is_same<typename std::decay<T>::type, std::nullptr_t>::value>::type
119 repr(
T &&, std::ostream &os = std::cout)
131 template <
class Ret,
class... Args>
132 void repr(Ret (*f)(Args...), std::ostream &os = std::cout)
135 os <<
"<function at " << (
void *)f <<
'>';
147 typename std::enable_if<
148 !std::is_same<typename std::decay<T>::type,
bool>::value &&
149 !is_string<typename std::decay<T>::type>::value &&
150 !is_char<typename std::decay<T>::type>::value &&
151 !std::is_function<typename std::decay<T>::type>::value &&
152 is_printable<typename std::decay<T>::type>::value>::type
153 repr(
T &&value, std::ostream &os = std::cout)
165 typename std::enable_if<
166 !std::is_same<typename std::decay<T>::type, std::nullptr_t>::value &&
167 !is_string<typename std::decay<T>::type>::value &&
168 !is_char<typename std::decay<T>::type>::value &&
169 !is_printable<typename std::decay<T>::type>::value>::type
170 repr(
T &&value, std::ostream &os = std::cout)
173 <<
tiname(
typeid(
typename std::decay<T>::type))
180 void repr(
T &&value, std::ostream &os = std::cout)
182 os << std::forward<T>(value);
enable_if_string< T > repr(T &&value, std::ostream &os=std::cout)
输出字符串类型(std::string, const char* 等)的表示,带双引号。
Definition repr.h:79
std::string tiname(const std::type_info &ti)
获取类型信息的可读名称(跨平台 demangle)。
Definition repr.h:56
typename std::enable_if< is_string< typename std::decay< T >::type >::value >::type enable_if_string
启用若 T(decay 后)是字符串类型。
Definition sfinae.h:337
typename std::enable_if< is_char< typename std::decay< T >::type >::value >::type enable_if_char
启用若 T(decay 后)是字符类型。
Definition sfinae.h:367
提供编译期类型特征检测(SFINAE 工具),用于判断容器、可调用对象、迭代器、下标访问、字符串、可打印类型、字符类型等。