From e3710ab97274682fed0c06aed3abd4f153678b1e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 2 May 2020 20:35:46 -0700 Subject: [PATCH 1/3] FMT_CONSTEXPR -> constexpr --- include/fmt/core.h | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 0bb974d9..b977f342 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -284,7 +284,7 @@ namespace internal { // A helper function to suppress bogus "conditional expression is constant" // warnings. -template FMT_CONSTEXPR T const_check(T value) { return value; } +template constexpr T const_check(T value) { return value; } // A workaround for gcc 4.8 to make void_t work in a SFINAE context. template struct void_t_impl { using type = void; }; @@ -368,10 +368,10 @@ template class basic_string_view { using value_type = Char; using iterator = const Char*; - FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} + constexpr basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} /** Constructs a string reference object from a C string and a size. */ - FMT_CONSTEXPR basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT + constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT : data_(s), size_(count) {} @@ -401,15 +401,15 @@ template class basic_string_view { size_(s.size()) {} /** Returns a pointer to the string data. */ - FMT_CONSTEXPR const Char* data() const { return data_; } + constexpr const Char* data() const { return data_; } /** Returns the string size. */ - FMT_CONSTEXPR size_t size() const { return size_; } + constexpr size_t size() const { return size_; } - FMT_CONSTEXPR iterator begin() const { return data_; } - FMT_CONSTEXPR iterator end() const { return data_ + size_; } + constexpr iterator begin() const { return data_; } + constexpr iterator end() const { return data_ + size_; } - FMT_CONSTEXPR const Char& operator[](size_t pos) const { return data_[pos]; } + constexpr const Char& operator[](size_t pos) const { return data_[pos]; } FMT_CONSTEXPR void remove_prefix(size_t n) { data_ += n; @@ -530,8 +530,8 @@ template struct char_t_impl::value>> { }; struct error_handler { - FMT_CONSTEXPR error_handler() = default; - FMT_CONSTEXPR error_handler(const error_handler&) = default; + constexpr error_handler() = default; + constexpr error_handler(const error_handler&) = default; // This function is intentionally not constexpr to give a compile-time error. FMT_NORETURN FMT_API void on_error(const char* message); @@ -567,7 +567,7 @@ class basic_format_parse_context : private ErrorHandler { using char_type = Char; using iterator = typename basic_string_view::iterator; - explicit FMT_CONSTEXPR basic_format_parse_context( + explicit constexpr basic_format_parse_context( basic_string_view format_str, ErrorHandler eh = {}) : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {} @@ -575,14 +575,12 @@ class basic_format_parse_context : private ErrorHandler { Returns an iterator to the beginning of the format string range being parsed. */ - FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT { - return format_str_.begin(); - } + constexpr iterator begin() const FMT_NOEXCEPT { return format_str_.begin(); } /** Returns an iterator past the end of the format string range being parsed. */ - FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT { return format_str_.end(); } + constexpr iterator end() const FMT_NOEXCEPT { return format_str_.end(); } /** Advances the begin iterator to ``it``. */ FMT_CONSTEXPR void advance_to(iterator it) { @@ -618,7 +616,7 @@ class basic_format_parse_context : private ErrorHandler { ErrorHandler::on_error(message); } - FMT_CONSTEXPR ErrorHandler error_handler() const { return *this; } + constexpr ErrorHandler error_handler() const { return *this; } }; using format_parse_context = basic_format_parse_context; @@ -886,11 +884,11 @@ FMT_TYPE_CONSTANT(const Char*, cstring_type); FMT_TYPE_CONSTANT(basic_string_view, string_type); FMT_TYPE_CONSTANT(const void*, pointer_type); -FMT_CONSTEXPR bool is_integral_type(type t) { +constexpr bool is_integral_type(type t) { return t > type::none_type && t <= type::last_integer_type; } -FMT_CONSTEXPR bool is_arithmetic_type(type t) { +constexpr bool is_arithmetic_type(type t) { return t > type::none_type && t <= type::last_numeric_type; } @@ -935,8 +933,8 @@ template class value { named_arg_value named_args; }; - FMT_CONSTEXPR FMT_INLINE value(int val = 0) : int_value(val) {} - FMT_CONSTEXPR FMT_INLINE value(unsigned val) : uint_value(val) {} + constexpr FMT_INLINE value(int val = 0) : int_value(val) {} + constexpr FMT_INLINE value(unsigned val) : uint_value(val) {} FMT_INLINE value(long long val) : long_long_value(val) {} FMT_INLINE value(unsigned long long val) : ulong_long_value(val) {} FMT_INLINE value(int128_t val) : int128_value(val) {} @@ -1162,9 +1160,9 @@ template class basic_format_arg { internal::custom_value custom_; }; - FMT_CONSTEXPR basic_format_arg() : type_(internal::type::none_type) {} + constexpr basic_format_arg() : type_(internal::type::none_type) {} - FMT_CONSTEXPR explicit operator bool() const FMT_NOEXCEPT { + constexpr explicit operator bool() const FMT_NOEXCEPT { return type_ != internal::type::none_type; } From b85e9ac38b77a919ab113e25efd7f6bf62195dfa Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 2 May 2020 21:06:03 -0700 Subject: [PATCH 2/3] Simplify vformat_to --- include/fmt/core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index b977f342..2e8d9675 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1760,8 +1760,8 @@ template , OutputIt vformat_to( OutputIt out, const S& format_str, basic_format_args>> args) { - using container = remove_reference_t; - internal::container_buffer buf((internal::get_container(out))); + auto& c = internal::get_container(out); + internal::container_buffer> buf(c); internal::vformat_to(buf, to_string_view(format_str), args); return out; } From cbb4cb8991f6f8ac1518e5c0d28d029a7288fcae Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 2 May 2020 21:09:51 -0700 Subject: [PATCH 3/3] Remove undocumented deprecated APIs --- include/fmt/core.h | 8 -------- include/fmt/format.h | 18 ------------------ 2 files changed, 26 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 2e8d9675..2e5a51fe 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -364,7 +364,6 @@ template class basic_string_view { size_t size_; public: - using char_type FMT_DEPRECATED_ALIAS = Char; using value_type = Char; using iterator = const Char*; @@ -638,11 +637,6 @@ struct formatter { formatter() = delete; }; -template -struct FMT_DEPRECATED convert_to_int - : bool_constant::value && - std::is_convertible::value> {}; - // Specifies if T has an enabled formatter specialization. A type can be // formattable even if it doesn't have a formatter e.g. via a conversion. template @@ -1401,8 +1395,6 @@ class format_arg_store : 0); public: - FMT_DEPRECATED static constexpr unsigned long long types = desc; - format_arg_store(const Args&... args) : #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 diff --git a/include/fmt/format.h b/include/fmt/format.h index 2c761094..a087ca31 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -226,11 +226,6 @@ FMT_END_NAMESPACE # define FMT_NUMERIC_ALIGN 1 #endif -// Enable the deprecated percent specifier. -#ifndef FMT_DEPRECATED_PERCENT -# define FMT_DEPRECATED_PERCENT 0 -#endif - FMT_BEGIN_NAMESPACE namespace internal { @@ -1086,7 +1081,6 @@ struct float_specs { sign_t sign : 8; bool upper : 1; bool locale : 1; - bool percent : 1; bool binary32 : 1; bool use_grisu : 1; bool showpoint : 1; @@ -1288,12 +1282,6 @@ FMT_CONSTEXPR float_specs parse_float_type_spec( result.format = float_format::fixed; result.showpoint |= specs.precision != 0; break; -#if FMT_DEPRECATED_PERCENT - case '%': - result.format = float_format::fixed; - result.percent = true; - break; -#endif case 'A': result.upper = true; FMT_FALLTHROUGH; @@ -1700,12 +1688,7 @@ template class basic_writer { } if (const_check(std::is_same())) fspecs.binary32 = true; fspecs.use_grisu = use_grisu(); - if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) value *= 100; int exp = format_float(promote_float(value), precision, fspecs, buffer); - if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) { - buffer.push_back('%'); - --exp; // Adjust decimal place position. - } fspecs.precision = precision; char_type point = fspecs.locale ? decimal_point(locale_) : static_cast('.'); @@ -1821,7 +1804,6 @@ class arg_formatter_base { protected: writer_type& writer() { return writer_; } - FMT_DEPRECATED format_specs* spec() { return specs_; } format_specs* specs() { return specs_; } iterator out() { return writer_.out(); }