visit -> visit_format_arg

This commit is contained in:
Victor Zverovich 2018-10-05 07:15:41 -07:00
parent cdf3fa08dc
commit f5480635c0
3 changed files with 26 additions and 16 deletions

View File

@ -753,7 +753,7 @@ class basic_format_arg {
template <typename Visitor, typename Ctx>
friend FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Ctx> &arg);
visit_format_arg(Visitor &&vis, const basic_format_arg<Ctx> &arg);
friend class basic_format_args<Context>;
friend class internal::arg_map<Context>;
@ -794,7 +794,7 @@ struct monostate {};
*/
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
visit_format_arg(Visitor &&vis, const basic_format_arg<Context> &arg) {
typedef typename Context::char_type char_type;
switch (arg.type_) {
case internal::none_type:
@ -831,6 +831,12 @@ FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
return vis(monostate());
}
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
return visit_format_arg(std::forward<Visitor>(vis), arg);
}
// Parsing context consisting of a format string range being parsed and an
// argument counter for automatic indexing.
template <typename Char, typename ErrorHandler = internal::error_handler>

View File

@ -1818,7 +1818,8 @@ template <template <typename> class Handler, typename T,
typename Context, typename ErrorHandler>
FMT_CONSTEXPR void set_dynamic_spec(
T &value, basic_format_arg<Context> arg, ErrorHandler eh) {
unsigned long long big_value = fmt::visit(Handler<ErrorHandler>(eh), arg);
unsigned long long big_value =
visit_format_arg(Handler<ErrorHandler>(eh), arg);
if (big_value > (std::numeric_limits<int>::max)())
eh.on_error("number is too big");
value = static_cast<T>(big_value);
@ -3224,7 +3225,7 @@ struct formatter<
specs_.precision_, specs_.precision_ref, ctx);
typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> range_type;
return fmt::visit(arg_formatter<range_type>(ctx, &specs_),
return visit_format_arg(arg_formatter<range_type>(ctx, &specs_),
internal::make_arg<FormatContext>(val));
}
@ -3285,7 +3286,7 @@ class dynamic_formatter {
checker.end_precision();
typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> range;
fmt::visit(arg_formatter<range>(ctx, &specs_),
visit_format_arg(arg_formatter<range>(ctx, &specs_),
internal::make_arg<FormatContext>(val));
return ctx.out();
}
@ -3341,14 +3342,16 @@ struct format_handler : internal::error_handler {
void on_replacement_field(const Char *p) {
context.parse_context().advance_to(p);
if (!fmt::visit(internal::custom_formatter<Char, Context>(context), arg))
context.advance_to(fmt::visit(ArgFormatter(context), arg));
internal::custom_formatter<Char, Context> f(context);
if (!visit_format_arg(f, arg))
context.advance_to(visit_format_arg(ArgFormatter(context), arg));
}
iterator on_format_specs(iterator it) {
auto &parse_ctx = context.parse_context();
parse_ctx.advance_to(pointer_from(it));
if (fmt::visit(internal::custom_formatter<Char, Context>(context), arg))
internal::custom_formatter<Char, Context> f(context);
if (visit_format_arg(f, arg))
return iterator(parse_ctx);
basic_format_specs<Char> specs;
using internal::specs_handler;
@ -3358,7 +3361,7 @@ struct format_handler : internal::error_handler {
if (*it != '}')
on_error("missing '}' in format string");
parse_ctx.advance_to(pointer_from(it));
context.advance_to(fmt::visit(ArgFormatter(context, &specs), arg));
context.advance_to(visit_format_arg(ArgFormatter(context, &specs), arg));
return it;
}

View File

@ -133,7 +133,7 @@ class arg_converter: public function<void> {
// unsigned).
template <typename T, typename Context, typename Char>
void convert_arg(basic_format_arg<Context> &arg, Char type) {
fmt::visit(arg_converter<T, Context>(arg, type), arg);
visit_format_arg(arg_converter<T, Context>(arg, type), arg);
}
// Converts an integer argument to char for printf.
@ -453,8 +453,8 @@ unsigned basic_printf_context<OutputIt, Char, AF>::parse_header(
spec.width_ = parse_nonnegative_int(it, eh);
} else if (*it == '*') {
++it;
spec.width_ =
fmt::visit(internal::printf_width_handler<char_type>(spec), get_arg(it));
spec.width_ = visit_format_arg(
internal::printf_width_handler<char_type>(spec), get_arg(it));
}
return arg_index;
}
@ -490,14 +490,14 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
} else if (*it == '*') {
++it;
spec.precision_ =
fmt::visit(internal::printf_precision_handler(), get_arg(it));
visit_format_arg(internal::printf_precision_handler(), get_arg(it));
} else {
spec.precision_ = 0;
}
}
format_arg arg = get_arg(it, arg_index);
if (spec.flag(HASH_FLAG) && fmt::visit(internal::is_zero_int(), arg))
if (spec.flag(HASH_FLAG) && visit_format_arg(internal::is_zero_int(), arg))
spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
if (spec.fill_ == '0') {
if (arg.is_arithmetic())
@ -551,7 +551,8 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
break;
case 'c':
// TODO: handle wchar_t better?
fmt::visit(internal::char_converter<basic_printf_context>(arg), arg);
visit_format_arg(
internal::char_converter<basic_printf_context>(arg), arg);
break;
}
}
@ -559,7 +560,7 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
start = it;
// Format argument.
fmt::visit(AF(buffer, spec, *this), arg);
visit_format_arg(AF(buffer, spec, *this), arg);
}
buffer.append(pointer_from(start), pointer_from(it));
}