Merge arg overloads and cleanup

This commit is contained in:
Victor Zverovich 2020-04-15 08:16:02 -07:00
parent c3fa333140
commit 567ed03f88

View File

@ -1558,15 +1558,13 @@ template <typename Context> class basic_format_args {
format_arg do_get(int index) const { format_arg do_get(int index) const {
format_arg arg; format_arg arg;
if (!is_packed()) { if (!is_packed()) {
auto num_args = max_size(); if (index < max_size()) arg = args_[index];
if (index < num_args) arg = args_[index];
return arg; return arg;
} }
if (index > internal::max_packed_args) return arg; if (index > internal::max_packed_args) return arg;
arg.type_ = type(index); arg.type_ = type(index);
if (arg.type_ == internal::type::none_type) return arg; if (arg.type_ == internal::type::none_type) return arg;
internal::value<Context>& val = arg.value_; arg.value_ = values_[index];
val = values_[index];
return arg; return arg;
} }
@ -1744,14 +1742,10 @@ inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
*/ */
template <typename S, typename T, typename Char = char_t<S>> template <typename S, typename T, typename Char = char_t<S>>
inline internal::named_arg<T, Char> arg(const S& name, const T& arg) { inline internal::named_arg<T, Char> arg(const S& name, const T& arg) {
static_assert(internal::is_string<S>::value, ""); static_assert(internal::is_string<S>() && !internal::is_named_arg<T>(), "");
return {name, arg}; return {name, arg};
} }
// Disable nested named arguments, e.g. ``arg("a", arg("b", 42))``.
template <typename S, typename T, typename Char>
void arg(S, internal::named_arg<T, Char>) = delete;
/** Formats a string and writes the output to ``out``. */ /** Formats a string and writes the output to ``out``. */
// GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with // GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with
// vformat_to<ArgFormatter>(...) overload, so SFINAE on iterator type instead. // vformat_to<ArgFormatter>(...) overload, so SFINAE on iterator type instead.
@ -1798,9 +1792,8 @@ inline std::basic_string<Char> vformat(
// std::basic_string<char_t<S>> to reduce the symbol size. // std::basic_string<char_t<S>> to reduce the symbol size.
template <typename S, typename... Args, typename Char = char_t<S>> template <typename S, typename... Args, typename Char = char_t<S>>
inline std::basic_string<Char> format(const S& format_str, Args&&... args) { inline std::basic_string<Char> format(const S& format_str, Args&&... args) {
return internal::vformat( const auto& vargs = internal::make_args_checked<Args...>(format_str, args...);
to_string_view(format_str), return internal::vformat(to_string_view(format_str), vargs);
internal::make_args_checked<Args...>(format_str, args...));
} }
FMT_API void vprint(string_view, format_args); FMT_API void vprint(string_view, format_args);
@ -1819,12 +1812,10 @@ FMT_API void vprint(std::FILE*, string_view, format_args);
*/ */
template <typename S, typename... Args, typename Char = char_t<S>> template <typename S, typename... Args, typename Char = char_t<S>>
inline void print(std::FILE* f, const S& format_str, Args&&... args) { inline void print(std::FILE* f, const S& format_str, Args&&... args) {
const auto& vargs = internal::make_args_checked<Args...>(format_str, args...);
return internal::is_unicode<Char>() return internal::is_unicode<Char>()
? vprint(f, to_string_view(format_str), ? vprint(f, to_string_view(format_str), vargs)
internal::make_args_checked<Args...>(format_str, args...)) : internal::vprint_mojibake(f, to_string_view(format_str), vargs);
: internal::vprint_mojibake(
f, to_string_view(format_str),
internal::make_args_checked<Args...>(format_str, args...));
} }
/** /**
@ -1840,12 +1831,11 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) {
*/ */
template <typename S, typename... Args, typename Char = char_t<S>> template <typename S, typename... Args, typename Char = char_t<S>>
inline void print(const S& format_str, Args&&... args) { inline void print(const S& format_str, Args&&... args) {
const auto& vargs = internal::make_args_checked<Args...>(format_str, args...);
return internal::is_unicode<Char>() return internal::is_unicode<Char>()
? vprint(to_string_view(format_str), ? vprint(to_string_view(format_str), vargs)
internal::make_args_checked<Args...>(format_str, args...))
: internal::vprint_mojibake( : internal::vprint_mojibake(
stdout, to_string_view(format_str), stdout, to_string_view(format_str), vargs);
internal::make_args_checked<Args...>(format_str, args...));
} }
FMT_END_NAMESPACE FMT_END_NAMESPACE