From 874d6727e4eeaa132aa3d078de5ada71a19b36da Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 13 Jun 2019 20:16:06 -0700 Subject: [PATCH] Remove workarounds for pre-C++11 compilers --- include/fmt/format.h | 38 +++++++------------------------------- include/fmt/printf.h | 12 +++++------- test/format | 4 +--- test/format-impl-test.cc | 4 ++-- test/format-test.cc | 4 +--- 5 files changed, 16 insertions(+), 46 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 3e248039..e0edd3f6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -265,31 +265,9 @@ inline Dest bit_cast(const Source& source) { return dest; } -// An implementation of begin and end for pre-C++11 compilers such as gcc 4. -template -FMT_CONSTEXPR auto begin(const C& c) -> decltype(c.begin()) { - return c.begin(); -} -template -FMT_CONSTEXPR T* begin(T (&array)[N]) FMT_NOEXCEPT { - return array; -} -template FMT_CONSTEXPR auto end(const C& c) -> decltype(c.end()) { - return c.end(); -} -template -FMT_CONSTEXPR T* end(T (&array)[N]) FMT_NOEXCEPT { - return array + N; -} - -// An implementation of iterator_t for pre-C++20 compilers such as gcc 4. +// An implementation of iterator_t for pre-C++20 systems. template struct iterator_t { - typedef decltype(internal::begin(std::declval())) type; -}; - -// For std::result_of in gcc 4.4. -template struct function { - template struct result { typedef Result type; }; + typedef decltype(std::begin(std::declval())) type; }; template @@ -1531,7 +1509,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char*& begin, return value; } -template class custom_formatter : public function { +template class custom_formatter { private: typedef typename Context::char_type char_type; @@ -1558,8 +1536,7 @@ template struct is_integer { }; }; -template -class width_checker : public function { +template class width_checker { public: explicit FMT_CONSTEXPR width_checker(ErrorHandler& eh) : handler_(eh) {} @@ -1579,8 +1556,7 @@ class width_checker : public function { ErrorHandler& handler_; }; -template -class precision_checker : public function { +template class precision_checker { public: explicit FMT_CONSTEXPR precision_checker(ErrorHandler& eh) : handler_(eh) {} @@ -3339,13 +3315,13 @@ arg_join join(It begin, It end, wstring_view sep) { template arg_join::type, char> join( const Range& range, string_view sep) { - return join(internal::begin(range), internal::end(range), sep); + return join(std::begin(range), std::end(range), sep); } template arg_join::type, wchar_t> join( const Range& range, wstring_view sep) { - return join(internal::begin(range), internal::end(range), sep); + return join(std::begin(range), std::end(range), sep); } #endif diff --git a/include/fmt/printf.h b/include/fmt/printf.h index c3a48ed4..d52f849c 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -38,7 +38,7 @@ template <> struct int_checker { static bool fits_in_int(int) { return true; } }; -class printf_precision_handler : public function { +class printf_precision_handler { public: template ::value)> int operator()(T value) { @@ -55,7 +55,7 @@ class printf_precision_handler : public function { }; // An argument visitor that returns true iff arg is a zero integer. -class is_zero_int : public function { +class is_zero_int { public: template ::value)> bool operator()(T value) { @@ -72,8 +72,7 @@ template struct make_unsigned_or_bool : std::make_unsigned {}; template <> struct make_unsigned_or_bool { typedef bool type; }; -template -class arg_converter : public function { +template class arg_converter { private: typedef typename Context::char_type Char; @@ -129,7 +128,7 @@ void convert_arg(basic_format_arg& arg, Char type) { } // Converts an integer argument to char for printf. -template class char_converter : public function { +template class char_converter { private: basic_format_arg& arg_; @@ -148,8 +147,7 @@ template class char_converter : public function { // Checks if an argument is a valid printf width specifier and sets // left alignment if it is negative. -template -class printf_width_handler : public function { +template class printf_width_handler { private: typedef basic_format_specs format_specs; diff --git a/test/format b/test/format index 53a7b5df..60dc60e5 100644 --- a/test/format +++ b/test/format @@ -489,9 +489,7 @@ namespace detail { template class arg_formatter - : public fmt::internal::function< - typename fmt::internal::arg_formatter_base::iterator>, - public fmt::internal::arg_formatter_base { + : public fmt::internal::arg_formatter_base { private: using char_type = typename Range::value_type; using base = fmt::internal::arg_formatter_base; diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 94bc5eea..2b0067b0 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -143,7 +143,7 @@ TEST(FPTest, GrisuFormatCompilesWithNonIEEEDouble) { grisu_format(4.2f, buf, -1, false, exp); } -template struct ValueExtractor : fmt::internal::function { +template struct value_extractor { T operator()(T value) { return value; } template FMT_NORETURN T operator()(U) { @@ -157,7 +157,7 @@ TEST(FormatTest, ArgConverter) { fmt::visit_format_arg( fmt::internal::arg_converter(arg, 'd'), arg); - EXPECT_EQ(value, fmt::visit_format_arg(ValueExtractor(), arg)); + EXPECT_EQ(value, fmt::visit_format_arg(value_extractor(), arg)); } TEST(FormatTest, FormatNegativeNaN) { diff --git a/test/format-test.cc b/test/format-test.cc index 0d7153e3..6c05854c 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1890,9 +1890,7 @@ TEST(FormatTest, FixedEnum) { EXPECT_EQ("0", fmt::format("{}", B)); } typedef fmt::back_insert_range> buffer_range; class mock_arg_formatter - : public fmt::internal::function< - fmt::internal::arg_formatter_base::iterator>, - public fmt::internal::arg_formatter_base { + : public fmt::internal::arg_formatter_base { private: MOCK_METHOD1(call, void(long long value));