From f6f0415b833e8ba32b7b641f00d01a7fd8dbb6be Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 7 Jul 2019 16:43:38 -0700 Subject: [PATCH] typedef -> using --- include/fmt/chrono.h | 12 +++--- include/fmt/format-inl.h | 8 ++-- include/fmt/posix.h | 12 +++--- include/fmt/printf.h | 85 +++++++++++++++++----------------------- include/fmt/ranges.h | 2 +- test/posix-mock-test.cc | 2 +- test/printf-test.cc | 8 ++-- 7 files changed, 58 insertions(+), 71 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index a71638e1..f19a5e96 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -506,12 +506,12 @@ struct chrono_formatter { conditional_t::value && sizeof(Rep) < sizeof(int), unsigned, typename make_unsigned_or_unchanged::type>; rep val; - typedef std::chrono::duration seconds; + using seconds = std::chrono::duration; seconds s; - typedef std::chrono::duration milliseconds; + using milliseconds = std::chrono::duration; bool negative; - typedef typename FormatContext::char_type char_type; + using char_type = typename FormatContext::char_type; explicit chrono_formatter(FormatContext& ctx, OutputIt o, std::chrono::duration d) @@ -717,11 +717,11 @@ struct formatter, Char> { private: basic_format_specs specs; int precision; - typedef internal::arg_ref arg_ref_type; + using arg_ref_type = internal::arg_ref; arg_ref_type width_ref; arg_ref_type precision_ref; mutable basic_string_view format_str; - typedef std::chrono::duration duration; + using duration = std::chrono::duration; struct spec_handler { formatter& f; @@ -759,7 +759,7 @@ struct formatter, Char> { } }; - typedef typename basic_parse_context::iterator iterator; + using iterator = typename basic_parse_context::iterator; struct parse_range { iterator begin; iterator end; diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 0b463131..f6fa29ab 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -78,7 +78,7 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) { # define FMT_SNPRINTF fmt_snprintf #endif // _MSC_VER -typedef void (*FormatFunc)(internal::buffer&, int, string_view); +using format_func = void (*)(internal::buffer&, int, string_view); // Portable thread-safe version of strerror. // Sets buffer to point to a string describing the error code. @@ -182,7 +182,7 @@ FMT_FUNC void fwrite_fully(const void* ptr, size_t size, size_t count, } } -FMT_FUNC void report_error(FormatFunc func, int error_code, +FMT_FUNC void report_error(format_func func, int error_code, string_view message) FMT_NOEXCEPT { memory_buffer full_message; func(full_message, error_code, message); @@ -355,7 +355,7 @@ template struct bits { // A handmade floating-point number f * pow(2, e). class fp { private: - typedef uint64_t significand_type; + using significand_type = uint64_t; // All sizes are in bits. // Subtract 1 to account for an implicit most significant bit in the @@ -379,7 +379,7 @@ class fp { // errors on platforms where double is not IEEE754. template explicit fp(Double d) { // Assume double is in the format [sign][exponent][significand]. - typedef std::numeric_limits limits; + using limits = std::numeric_limits; const int exponent_size = bits::value - double_significand_size - 1; // -1 for sign const uint64_t significand_mask = implicit_bit - 1; diff --git a/include/fmt/posix.h b/include/fmt/posix.h index e5394f40..9876ce9a 100644 --- a/include/fmt/posix.h +++ b/include/fmt/posix.h @@ -69,7 +69,7 @@ FMT_BEGIN_NAMESPACE A reference to a null-terminated string. It can be constructed from a C string or ``std::string``. - You can use one of the following typedefs for common character types: + You can use one of the following type aliases for common character types: +---------------+-----------------------------+ | Type | Definition | @@ -108,8 +108,8 @@ template class basic_cstring_view { const Char* c_str() const { return data_; } }; -typedef basic_cstring_view cstring_view; -typedef basic_cstring_view wcstring_view; +using cstring_view = basic_cstring_view; +using wcstring_view = basic_cstring_view; // An error code. class error_code { @@ -266,7 +266,7 @@ long getpagesize(); class Locale { private: # ifdef _MSC_VER - typedef _locale_t locale_t; + using locale_t = _locale_t; enum { LC_NUMERIC_MASK = LC_NUMERIC }; @@ -287,14 +287,14 @@ class Locale { void operator=(const Locale&) = delete; public: - typedef locale_t Type; + using type = locale_t; Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", nullptr)) { if (!locale_) FMT_THROW(system_error(errno, "cannot create locale")); } ~Locale() { freelocale(locale_); } - Type get() const { return locale_; } + type get() const { return locale_; } // Converts string to floating-point number and advances str past the end // of the parsed input. diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 77c2ee8f..267724a7 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -70,17 +70,17 @@ class is_zero_int { template struct make_unsigned_or_bool : std::make_unsigned {}; -template <> struct make_unsigned_or_bool { typedef bool type; }; +template <> struct make_unsigned_or_bool { using type = bool; }; template class arg_converter { private: - typedef typename Context::char_type Char; + using char_type = typename Context::char_type; basic_format_arg& arg_; - typename Context::char_type type_; + char_type type_; public: - arg_converter(basic_format_arg& arg, Char type) + arg_converter(basic_format_arg& arg, char_type type) : arg_(arg), type_(type) {} void operator()(bool value) { @@ -97,9 +97,9 @@ template class arg_converter { arg_ = internal::make_arg( static_cast(static_cast(value))); } else { - typedef typename make_unsigned_or_bool::type Unsigned; + using unsigned_type = typename make_unsigned_or_bool::type; arg_ = internal::make_arg( - static_cast(static_cast(value))); + static_cast(static_cast(value))); } } else { if (is_signed) { @@ -137,8 +137,8 @@ template class char_converter { template ::value)> void operator()(T value) { - typedef typename Context::char_type Char; - arg_ = internal::make_arg(static_cast(value)); + arg_ = internal::make_arg( + static_cast(value)); } template ::value)> @@ -149,7 +149,7 @@ template class char_converter { // left alignment if it is negative. template class printf_width_handler { private: - typedef basic_format_specs format_specs; + using format_specs = basic_format_specs; format_specs& specs_; @@ -203,12 +203,12 @@ template class basic_printf_context; template class printf_arg_formatter : public internal::arg_formatter_base { public: - typedef decltype(std::declval().begin()) iterator; + using iterator = typename Range::iterator; private: - typedef typename Range::value_type char_type; - typedef internal::arg_formatter_base base; - typedef basic_printf_context context_type; + using char_type = typename Range::value_type; + using base = internal::arg_formatter_base; + using context_type = basic_printf_context; context_type& context_; @@ -223,7 +223,7 @@ class printf_arg_formatter : public internal::arg_formatter_base { } public: - typedef typename base::format_specs format_specs; + using format_specs = typename base::format_specs; /** \rst @@ -328,7 +328,7 @@ template class basic_printf_context { template using formatter_type = printf_formatter; private: - typedef basic_format_specs format_specs; + using format_specs = basic_format_specs; OutputIt out_; basic_format_args args_; @@ -563,17 +563,15 @@ OutputIt basic_printf_context::format() { return std::copy(start, it, out); } -template struct basic_printf_context_t { - typedef basic_printf_context, - typename Buffer::value_type> - type; -}; +template using basic_printf_context_t = + basic_printf_context>, + Char>; -typedef basic_printf_context_t>::type printf_context; -typedef basic_printf_context_t>::type wprintf_context; +using printf_context = basic_printf_context_t; +using wprintf_context = basic_printf_context_t; -typedef basic_format_args printf_args; -typedef basic_format_args wprintf_args; +using printf_args = basic_format_args; +using wprintf_args = basic_format_args; /** \rst @@ -602,9 +600,7 @@ inline format_arg_store make_wprintf_args( template > inline std::basic_string vsprintf( const S& format, - basic_format_args< - typename basic_printf_context_t>::type> - args) { + basic_format_args> args) { basic_memory_buffer buffer; printf(buffer, to_string_view(format), args); return to_string(buffer); @@ -622,17 +618,14 @@ inline std::basic_string vsprintf( template ::value, char_t>> inline std::basic_string sprintf(const S& format, const Args&... args) { - using context = typename basic_printf_context_t>::type; - format_arg_store as{args...}; - return vsprintf(to_string_view(format), basic_format_args(as)); + using context = basic_printf_context_t; + return vsprintf(to_string_view(format), {make_format_args(args...)}); } template > inline int vfprintf( std::FILE* f, const S& format, - basic_format_args< - typename basic_printf_context_t>::type> - args) { + basic_format_args> args) { basic_memory_buffer buffer; printf(buffer, to_string_view(format), args); std::size_t size = buffer.size(); @@ -653,17 +646,15 @@ inline int vfprintf( template ::value, char_t>> inline int fprintf(std::FILE* f, const S& format, const Args&... args) { - using context = typename basic_printf_context_t>::type; - format_arg_store as{args...}; - return vfprintf(f, to_string_view(format), basic_format_args(as)); + using context = basic_printf_context_t; + return vfprintf(f, to_string_view(format), + {make_format_args(args...)}); } template > inline int vprintf( const S& format, - basic_format_args< - typename basic_printf_context_t>::type> - args) { + basic_format_args> args) { return vfprintf(stdout, to_string_view(format), args); } @@ -679,18 +670,15 @@ inline int vprintf( template ::value)> inline int printf(const S& format_str, const Args&... args) { - using buffer = internal::buffer>; - using context = typename basic_printf_context_t::type; - format_arg_store as{args...}; - return vprintf(to_string_view(format_str), basic_format_args(as)); + using context = basic_printf_context_t>; + return vprintf(to_string_view(format_str), + {make_format_args(args...)}); } template > inline int vfprintf( std::basic_ostream& os, const S& format, - basic_format_args< - typename basic_printf_context_t>::type> - args) { + basic_format_args> args) { basic_memory_buffer buffer; printf(buffer, to_string_view(format), args); internal::write(os, buffer); @@ -721,10 +709,9 @@ typename ArgFormatter::iterator vprintf(internal::buffer& out, template > inline int fprintf(std::basic_ostream& os, const S& format_str, const Args&... args) { - using context = typename basic_printf_context_t>::type; - format_arg_store as{args...}; + using context = basic_printf_context_t; return vfprintf(os, to_string_view(format_str), - basic_format_args(as)); + {make_format_args(args...)}); } FMT_END_NAMESPACE diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 9128f25a..e6540108 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -124,7 +124,7 @@ template using make_index_sequence = std::make_index_sequence; #else template struct integer_sequence { - typedef T value_type; + using value_type = T; static FMT_CONSTEXPR std::size_t size() { return sizeof...(N); } }; diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index 1cee9fd1..58e015aa 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -446,7 +446,7 @@ TEST(ScopedMock, Scope) { #ifdef FMT_LOCALE -typedef fmt::Locale::Type LocaleType; +typedef fmt::Locale::type LocaleType; struct LocaleMock { static LocaleMock* instance; diff --git a/test/printf-test.cc b/test/printf-test.cc index e2528912..aa25a592 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -535,11 +535,11 @@ TEST(PrintfTest, VSPrintfMakeArgsExample) { fmt::basic_format_args args2(as2); EXPECT_EQ("[42] something happened", fmt::vsprintf("[%d] %s happened", args2)); - // the older gcc versions can't cast the return value + // The older gcc versions can't cast the return value. #if !defined(__GNUC__) || (__GNUC__ > 4) EXPECT_EQ("[42] something happened", fmt::vsprintf("[%d] %s happened", - fmt::make_printf_args(42, "something"))); + {fmt::make_printf_args(42, "something")})); #endif } @@ -557,7 +557,7 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) { #if !defined(__GNUC__) || (__GNUC__ > 4) EXPECT_EQ(L"[42] something happened", fmt::vsprintf(L"[%d] %s happened", - fmt::make_wprintf_args(42, L"something"))); + {fmt::make_wprintf_args(42, L"something")})); #endif } @@ -601,7 +601,7 @@ std::string custom_vformat(fmt::string_view format_str, format_args_t args) { template std::string custom_format(const char* format_str, const Args&... args) { auto va = fmt::make_printf_args(args...); - return custom_vformat(format_str, va); + return custom_vformat(format_str, {va}); } TEST(PrintfTest, CustomFormat) {