|
Console Library 8.0.0
A header-only library that makes C++ simple
|
提供类似 Python 的 repr() 函数,用于生成对象的可读字符串表示。 More...
#include <iostream>#include <memory>#include <string>#include <typeinfo>#include "../core/sfinae.h"#include "./strpp.h"Go to the source code of this file.
Namespaces | |
| namespace | console |
| 本库所有组件所在的顶层命名空间。 | |
Functions | |
| std::string | console::tiname_impl (const std::type_info &ti) |
| 获取类型信息的可读名称(跨平台 demangle),返回 std::string。 | |
| std::string | console::tiname (const std::type_info &ti) |
| tiname_impl 的 char 版别名。 | |
| std::wstring | console::wtiname (const std::type_info &ti) |
| tiname_impl 的 wchar_t 版。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| std::enable_if< is_string< typenamestd::decay< T >::type >::value >::type | console::repr (T &&value, std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出字符串类型(std::string, const char* 等)的表示,带双引号。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| std::enable_if< is_char< typenamestd::decay< T >::type >::value >::type | console::repr (T &&value, std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出字符类型的表示,带单引号。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| std::enable_if< std::is_same< typenamestd::decay< T >::type, bool >::value >::type | console::repr (T &&value, std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出布尔值的表示("true" 或 "false")。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| std::enable_if< std::is_same< typenamestd::decay< T >::type, std::nullptr_t >::value >::type | console::repr (T &&, std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出 nullptr 的表示。 | |
| template<class CharT, class Traits, class Ret, class... Args> | |
| void | console::repr (Ret(*f)(Args...), std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出函数指针的表示,格式为 "<function at 地址>"。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| std::enable_if<!std::is_same< typenamestd::decay< T >::type, bool >::value &&!std::is_same< typenamestd::decay< T >::type, std::nullptr_t >::value &&!is_string< typenamestd::decay< T >::type >::value &&!is_char< typenamestd::decay< T >::type >::value &&!std::is_function< typenamestd::remove_pointer< T >::type >::value &&is_basic_printable< CharT, Traits, typenamestd::decay< T >::type >::value >::type | console::repr (T &&value, std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出可打印类型(定义了 operator<<)的表示,直接输出值。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| std::enable_if<!std::is_same< typenamestd::decay< T >::type, std::nullptr_t >::value &&!is_string< typenamestd::decay< T >::type >::value &&!is_char< typenamestd::decay< T >::type >::value &&!is_basic_printable< CharT, Traits, typenamestd::decay< T >::type >::value >::type | console::repr (T &&value, std::basic_ostream< CharT, Traits > &os=std::cout) |
| 输出不可打印类型的表示,格式为 "<'类型名' object at 地址>"。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>> | |
| void | console::repr (std::reference_wrapper< T > v, std::basic_ostream< CharT, Traits > &os=std::cout) |
提供类似 Python 的 repr() 函数,用于生成对象的可读字符串表示。
该头文件通过 SFINAE 技术重载 repr 函数,支持字符串、字符、布尔值、nullptr、函数指针、 可打印类型(有 operator<<)以及不可打印类型(输出类型信息及地址)。