From a4fb9fa4131e38a279375308e4118e5084f448b0 Mon Sep 17 00:00:00 2001 From: Liyan Zheng Date: Tue, 9 Aug 2022 20:16:39 +0800 Subject: [PATCH] Chore: format dbg --- include/nnet/dbg.h | 841 ++++++++++++++++++++++----------------------- 1 file changed, 403 insertions(+), 438 deletions(-) diff --git a/include/nnet/dbg.h b/include/nnet/dbg.h index f5deb180..f5894e4b 100644 --- a/include/nnet/dbg.h +++ b/include/nnet/dbg.h @@ -72,13 +72,9 @@ License (MIT): namespace dbg { #ifdef DBG_MACRO_UNIX -inline bool isColorizedOutputEnabled() { - return isatty(fileno(stderr)); -} +inline bool isColorizedOutputEnabled() { return isatty(fileno(stderr)); } #else -inline bool isColorizedOutputEnabled() { - return true; -} +inline bool isColorizedOutputEnabled() { return true; } #endif struct time {}; @@ -107,154 +103,143 @@ static constexpr size_t SUFFIX_LENGTH = sizeof(">(void)") - 1; #error "This compiler is currently not supported by dbg_macro." #endif -} // namespace pretty_function +} // namespace pretty_function // Formatting helpers -template -struct print_formatted { - static_assert(std::is_integral::value, - "Only integral types are supported."); +template struct print_formatted { + static_assert(std::is_integral::value, + "Only integral types are supported."); - print_formatted(T value, int numeric_base) - : inner(value), base(numeric_base) {} + print_formatted(T value, int numeric_base) + : inner(value), base(numeric_base) {} - operator T() const { return inner; } + operator T() const { return inner; } - const char* prefix() const { - switch (base) { - case 8: - return "0o"; - case 16: - return "0x"; - case 2: - return "0b"; - default: - return ""; + const char *prefix() const { + switch (base) { + case 8: + return "0o"; + case 16: + return "0x"; + case 2: + return "0b"; + default: + return ""; + } } - } - T inner; - int base; + T inner; + int base; }; -template -print_formatted hex(T value) { - return print_formatted{value, 16}; +template print_formatted hex(T value) { + return print_formatted{value, 16}; } -template -print_formatted oct(T value) { - return print_formatted{value, 8}; +template print_formatted oct(T value) { + return print_formatted{value, 8}; } -template -print_formatted bin(T value) { - return print_formatted{value, 2}; +template print_formatted bin(T value) { + return print_formatted{value, 2}; } // Implementation of 'type_name()' -template -const char* type_name_impl() { - return DBG_MACRO_PRETTY_FUNCTION; +template const char *type_name_impl() { + return DBG_MACRO_PRETTY_FUNCTION; } -template -struct type_tag {}; +template struct type_tag {}; -template +template std::string get_type_name(type_tag) { - namespace pf = pretty_function; + namespace pf = pretty_function; - std::string type = type_name_impl(); - return type.substr(pf::PREFIX_LENGTH, - type.size() - pf::PREFIX_LENGTH - pf::SUFFIX_LENGTH); + std::string type = type_name_impl(); + return type.substr(pf::PREFIX_LENGTH, + type.size() - pf::PREFIX_LENGTH - pf::SUFFIX_LENGTH); } -template -std::string type_name() { - if (std::is_volatile::value) { - if (std::is_pointer::value) { - return type_name::type>() + " volatile"; - } else { - return "volatile " + type_name::type>(); +template std::string type_name() { + if (std::is_volatile::value) { + if (std::is_pointer::value) { + return type_name::type>() + + " volatile"; + } else { + return "volatile " + + type_name::type>(); + } } - } - if (std::is_const::value) { - if (std::is_pointer::value) { - return type_name::type>() + " const"; - } else { - return "const " + type_name::type>(); + if (std::is_const::value) { + if (std::is_pointer::value) { + return type_name::type>() + " const"; + } else { + return "const " + type_name::type>(); + } } - } - if (std::is_pointer::value) { - return type_name::type>() + "*"; - } - if (std::is_lvalue_reference::value) { - return type_name::type>() + "&"; - } - if (std::is_rvalue_reference::value) { - return type_name::type>() + "&&"; - } - return get_type_name(type_tag{}); + if (std::is_pointer::value) { + return type_name::type>() + "*"; + } + if (std::is_lvalue_reference::value) { + return type_name::type>() + "&"; + } + if (std::is_rvalue_reference::value) { + return type_name::type>() + "&&"; + } + return get_type_name(type_tag{}); } -inline std::string get_type_name(type_tag) { - return "short"; -} +inline std::string get_type_name(type_tag) { return "short"; } inline std::string get_type_name(type_tag) { - return "unsigned short"; + return "unsigned short"; } -inline std::string get_type_name(type_tag) { - return "long"; -} +inline std::string get_type_name(type_tag) { return "long"; } inline std::string get_type_name(type_tag) { - return "unsigned long"; + return "unsigned long"; } inline std::string get_type_name(type_tag) { - return "std::string"; + return "std::string"; } template std::string get_type_name(type_tag>>) { - return "std::vector<" + type_name() + ">"; + return "std::vector<" + type_name() + ">"; } template std::string get_type_name(type_tag>) { - return "std::pair<" + type_name() + ", " + type_name() + ">"; + return "std::pair<" + type_name() + ", " + type_name() + ">"; } -template -std::string type_list_to_string() { - std::string result; - auto unused = {(result += type_name() + ", ", 0)..., 0}; - static_cast(unused); +template std::string type_list_to_string() { + std::string result; + auto unused = {(result += type_name() + ", ", 0)..., 0}; + static_cast(unused); #if DBG_MACRO_CXX_STANDARD >= 17 - if constexpr (sizeof...(T) > 0) { + if constexpr (sizeof...(T) > 0) { #else - if (sizeof...(T) > 0) { + if (sizeof...(T) > 0) { #endif - result.pop_back(); - result.pop_back(); - } - return result; + result.pop_back(); + result.pop_back(); + } + return result; } -template -std::string get_type_name(type_tag>) { - return "std::tuple<" + type_list_to_string() + ">"; +template std::string get_type_name(type_tag>) { + return "std::tuple<" + type_list_to_string() + ">"; } template inline std::string get_type_name(type_tag>) { - return type_name(); + return type_name(); } // Implementation of 'is_detected' to specialize for container-like types @@ -262,36 +247,33 @@ inline std::string get_type_name(type_tag>) { namespace detail_detector { struct nonesuch { - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch(nonesuch const&) = delete; - void operator=(nonesuch const&) = delete; + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const &) = delete; + void operator=(nonesuch const &) = delete; }; -template -using void_t = void; +template using void_t = void; -template - class Op, +template class Op, class... Args> struct detector { - using value_t = std::false_type; - using type = Default; + using value_t = std::false_type; + using type = Default; }; template class Op, class... Args> struct detector>, Op, Args...> { - using value_t = std::true_type; - using type = Op; + using value_t = std::true_type; + using type = Op; }; -} // namespace detail_detector +} // namespace detail_detector template