sync with upstream

This commit is contained in:
James Beach 2020-05-03 08:52:12 +01:00
commit c2ad86fe11
2 changed files with 22 additions and 50 deletions

View File

@ -284,7 +284,7 @@ namespace internal {
// A helper function to suppress bogus "conditional expression is constant" // A helper function to suppress bogus "conditional expression is constant"
// warnings. // warnings.
template <typename T> FMT_CONSTEXPR T const_check(T value) { return value; } template <typename T> constexpr T const_check(T value) { return value; }
// A workaround for gcc 4.8 to make void_t work in a SFINAE context. // A workaround for gcc 4.8 to make void_t work in a SFINAE context.
template <typename... Ts> struct void_t_impl { using type = void; }; template <typename... Ts> struct void_t_impl { using type = void; };
@ -364,14 +364,13 @@ template <typename Char> class basic_string_view {
size_t size_; size_t size_;
public: public:
using char_type FMT_DEPRECATED_ALIAS = Char;
using value_type = Char; using value_type = Char;
using iterator = const 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. */ /** 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), : data_(s),
size_(count) {} size_(count) {}
@ -401,15 +400,15 @@ template <typename Char> class basic_string_view {
size_(s.size()) {} size_(s.size()) {}
/** Returns a pointer to the string data. */ /** 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. */ /** 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_; } constexpr iterator begin() const { return data_; }
FMT_CONSTEXPR iterator end() const { return data_ + size_; } 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) { FMT_CONSTEXPR void remove_prefix(size_t n) {
data_ += n; data_ += n;
@ -530,8 +529,8 @@ template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
}; };
struct error_handler { struct error_handler {
FMT_CONSTEXPR error_handler() = default; constexpr error_handler() = default;
FMT_CONSTEXPR error_handler(const error_handler&) = default; constexpr error_handler(const error_handler&) = default;
// This function is intentionally not constexpr to give a compile-time error. // This function is intentionally not constexpr to give a compile-time error.
FMT_NORETURN FMT_API void on_error(const char* message); FMT_NORETURN FMT_API void on_error(const char* message);
@ -567,7 +566,7 @@ class basic_format_parse_context : private ErrorHandler {
using char_type = Char; using char_type = Char;
using iterator = typename basic_string_view<Char>::iterator; using iterator = typename basic_string_view<Char>::iterator;
explicit FMT_CONSTEXPR basic_format_parse_context( explicit constexpr basic_format_parse_context(
basic_string_view<Char> format_str, ErrorHandler eh = {}) basic_string_view<Char> format_str, ErrorHandler eh = {})
: ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {} : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {}
@ -575,14 +574,12 @@ class basic_format_parse_context : private ErrorHandler {
Returns an iterator to the beginning of the format string range being Returns an iterator to the beginning of the format string range being
parsed. parsed.
*/ */
FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT { constexpr iterator begin() const FMT_NOEXCEPT { return format_str_.begin(); }
return format_str_.begin();
}
/** /**
Returns an iterator past the end of the format string range being parsed. 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``. */ /** Advances the begin iterator to ``it``. */
FMT_CONSTEXPR void advance_to(iterator it) { FMT_CONSTEXPR void advance_to(iterator it) {
@ -618,7 +615,7 @@ class basic_format_parse_context : private ErrorHandler {
ErrorHandler::on_error(message); 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<char>; using format_parse_context = basic_format_parse_context<char>;
@ -640,11 +637,6 @@ struct formatter {
formatter() = delete; formatter() = delete;
}; };
template <typename T, typename Char, typename Enable = void>
struct FMT_DEPRECATED convert_to_int
: bool_constant<!std::is_arithmetic<T>::value &&
std::is_convertible<T, int>::value> {};
// Specifies if T has an enabled formatter specialization. A type can be // 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. // formattable even if it doesn't have a formatter e.g. via a conversion.
template <typename T, typename Context> template <typename T, typename Context>
@ -886,11 +878,11 @@ FMT_TYPE_CONSTANT(const Char*, cstring_type);
FMT_TYPE_CONSTANT(basic_string_view<Char>, string_type); FMT_TYPE_CONSTANT(basic_string_view<Char>, string_type);
FMT_TYPE_CONSTANT(const void*, pointer_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; 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; return t > type::none_type && t <= type::last_numeric_type;
} }
@ -935,8 +927,8 @@ template <typename Context> class value {
named_arg_value<char_type> named_args; named_arg_value<char_type> named_args;
}; };
FMT_CONSTEXPR FMT_INLINE value(int val = 0) : int_value(val) {} constexpr FMT_INLINE value(int val = 0) : int_value(val) {}
FMT_CONSTEXPR FMT_INLINE value(unsigned val) : uint_value(val) {} constexpr FMT_INLINE value(unsigned val) : uint_value(val) {}
FMT_INLINE value(long long val) : long_long_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(unsigned long long val) : ulong_long_value(val) {}
FMT_INLINE value(int128_t val) : int128_value(val) {} FMT_INLINE value(int128_t val) : int128_value(val) {}
@ -1162,9 +1154,9 @@ template <typename Context> class basic_format_arg {
internal::custom_value<Context> custom_; internal::custom_value<Context> 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; return type_ != internal::type::none_type;
} }
@ -1403,8 +1395,6 @@ class format_arg_store
: 0); : 0);
public: public:
FMT_DEPRECATED static constexpr unsigned long long types = desc;
format_arg_store(const Args&... args) format_arg_store(const Args&... args)
: :
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
@ -1762,8 +1752,8 @@ template <typename OutputIt, typename S, typename Char = char_t<S>,
OutputIt vformat_to( OutputIt vformat_to(
OutputIt out, const S& format_str, OutputIt out, const S& format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args) { basic_format_args<buffer_context<type_identity_t<Char>>> args) {
using container = remove_reference_t<decltype(internal::get_container(out))>; auto& c = internal::get_container(out);
internal::container_buffer<container> buf((internal::get_container(out))); internal::container_buffer<remove_reference_t<decltype(c)>> buf(c);
internal::vformat_to(buf, to_string_view(format_str), args); internal::vformat_to(buf, to_string_view(format_str), args);
return out; return out;
} }

View File

@ -226,11 +226,6 @@ FMT_END_NAMESPACE
# define FMT_NUMERIC_ALIGN 1 # define FMT_NUMERIC_ALIGN 1
#endif #endif
// Enable the deprecated percent specifier.
#ifndef FMT_DEPRECATED_PERCENT
# define FMT_DEPRECATED_PERCENT 0
#endif
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
@ -1086,7 +1081,6 @@ struct float_specs {
sign_t sign : 8; sign_t sign : 8;
bool upper : 1; bool upper : 1;
bool locale : 1; bool locale : 1;
bool percent : 1;
bool binary32 : 1; bool binary32 : 1;
bool use_grisu : 1; bool use_grisu : 1;
bool showpoint : 1; bool showpoint : 1;
@ -1288,12 +1282,6 @@ FMT_CONSTEXPR float_specs parse_float_type_spec(
result.format = float_format::fixed; result.format = float_format::fixed;
result.showpoint |= specs.precision != 0; result.showpoint |= specs.precision != 0;
break; break;
#if FMT_DEPRECATED_PERCENT
case '%':
result.format = float_format::fixed;
result.percent = true;
break;
#endif
case 'A': case 'A':
result.upper = true; result.upper = true;
FMT_FALLTHROUGH; FMT_FALLTHROUGH;
@ -1700,12 +1688,7 @@ template <typename Range> class basic_writer {
} }
if (const_check(std::is_same<T, float>())) fspecs.binary32 = true; if (const_check(std::is_same<T, float>())) fspecs.binary32 = true;
fspecs.use_grisu = use_grisu<T>(); fspecs.use_grisu = use_grisu<T>();
if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) value *= 100;
int exp = format_float(promote_float(value), precision, fspecs, buffer); 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; fspecs.precision = precision;
char_type point = fspecs.locale ? decimal_point<char_type>(locale_) char_type point = fspecs.locale ? decimal_point<char_type>(locale_)
: static_cast<char_type>('.'); : static_cast<char_type>('.');
@ -1821,7 +1804,6 @@ class arg_formatter_base {
protected: protected:
writer_type& writer() { return writer_; } writer_type& writer() { return writer_; }
FMT_DEPRECATED format_specs* spec() { return specs_; }
format_specs* specs() { return specs_; } format_specs* specs() { return specs_; }
iterator out() { return writer_.out(); } iterator out() { return writer_.out(); }