Commit f5480635 authored by Victor Zverovich's avatar Victor Zverovich

visit -> visit_format_arg

parent cdf3fa08
...@@ -753,7 +753,7 @@ class basic_format_arg { ...@@ -753,7 +753,7 @@ class basic_format_arg {
template <typename Visitor, typename Ctx> template <typename Visitor, typename Ctx>
friend FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type 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 basic_format_args<Context>;
friend class internal::arg_map<Context>; friend class internal::arg_map<Context>;
...@@ -794,7 +794,7 @@ struct monostate {}; ...@@ -794,7 +794,7 @@ struct monostate {};
*/ */
template <typename Visitor, typename Context> template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type 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; typedef typename Context::char_type char_type;
switch (arg.type_) { switch (arg.type_) {
case internal::none_type: case internal::none_type:
...@@ -831,6 +831,12 @@ FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type ...@@ -831,6 +831,12 @@ FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
return vis(monostate()); 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 // Parsing context consisting of a format string range being parsed and an
// argument counter for automatic indexing. // argument counter for automatic indexing.
template <typename Char, typename ErrorHandler = internal::error_handler> template <typename Char, typename ErrorHandler = internal::error_handler>
......
...@@ -1818,7 +1818,8 @@ template <template <typename> class Handler, typename T, ...@@ -1818,7 +1818,8 @@ template <template <typename> class Handler, typename T,
typename Context, typename ErrorHandler> typename Context, typename ErrorHandler>
FMT_CONSTEXPR void set_dynamic_spec( FMT_CONSTEXPR void set_dynamic_spec(
T &value, basic_format_arg<Context> arg, ErrorHandler eh) { 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)()) if (big_value > (std::numeric_limits<int>::max)())
eh.on_error("number is too big"); eh.on_error("number is too big");
value = static_cast<T>(big_value); value = static_cast<T>(big_value);
...@@ -3224,7 +3225,7 @@ struct formatter< ...@@ -3224,7 +3225,7 @@ struct formatter<
specs_.precision_, specs_.precision_ref, ctx); specs_.precision_, specs_.precision_ref, ctx);
typedef output_range<typename FormatContext::iterator, typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> range_type; 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)); internal::make_arg<FormatContext>(val));
} }
...@@ -3285,7 +3286,7 @@ class dynamic_formatter { ...@@ -3285,7 +3286,7 @@ class dynamic_formatter {
checker.end_precision(); checker.end_precision();
typedef output_range<typename FormatContext::iterator, typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> range; 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)); internal::make_arg<FormatContext>(val));
return ctx.out(); return ctx.out();
} }
...@@ -3341,14 +3342,16 @@ struct format_handler : internal::error_handler { ...@@ -3341,14 +3342,16 @@ struct format_handler : internal::error_handler {
void on_replacement_field(const Char *p) { void on_replacement_field(const Char *p) {
context.parse_context().advance_to(p); context.parse_context().advance_to(p);
if (!fmt::visit(internal::custom_formatter<Char, Context>(context), arg)) internal::custom_formatter<Char, Context> f(context);
context.advance_to(fmt::visit(ArgFormatter(context), arg)); if (!visit_format_arg(f, arg))
context.advance_to(visit_format_arg(ArgFormatter(context), arg));
} }
iterator on_format_specs(iterator it) { iterator on_format_specs(iterator it) {
auto &parse_ctx = context.parse_context(); auto &parse_ctx = context.parse_context();
parse_ctx.advance_to(pointer_from(it)); 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); return iterator(parse_ctx);
basic_format_specs<Char> specs; basic_format_specs<Char> specs;
using internal::specs_handler; using internal::specs_handler;
...@@ -3358,7 +3361,7 @@ struct format_handler : internal::error_handler { ...@@ -3358,7 +3361,7 @@ struct format_handler : internal::error_handler {
if (*it != '}') if (*it != '}')
on_error("missing '}' in format string"); on_error("missing '}' in format string");
parse_ctx.advance_to(pointer_from(it)); 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; return it;
} }
......
...@@ -133,7 +133,7 @@ class arg_converter: public function<void> { ...@@ -133,7 +133,7 @@ class arg_converter: public function<void> {
// unsigned). // unsigned).
template <typename T, typename Context, typename Char> template <typename T, typename Context, typename Char>
void convert_arg(basic_format_arg<Context> &arg, Char type) { 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. // Converts an integer argument to char for printf.
...@@ -453,8 +453,8 @@ unsigned basic_printf_context<OutputIt, Char, AF>::parse_header( ...@@ -453,8 +453,8 @@ unsigned basic_printf_context<OutputIt, Char, AF>::parse_header(
spec.width_ = parse_nonnegative_int(it, eh); spec.width_ = parse_nonnegative_int(it, eh);
} else if (*it == '*') { } else if (*it == '*') {
++it; ++it;
spec.width_ = spec.width_ = visit_format_arg(
fmt::visit(internal::printf_width_handler<char_type>(spec), get_arg(it)); internal::printf_width_handler<char_type>(spec), get_arg(it));
} }
return arg_index; return arg_index;
} }
...@@ -490,14 +490,14 @@ void basic_printf_context<OutputIt, Char, AF>::format() { ...@@ -490,14 +490,14 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
} else if (*it == '*') { } else if (*it == '*') {
++it; ++it;
spec.precision_ = spec.precision_ =
fmt::visit(internal::printf_precision_handler(), get_arg(it)); visit_format_arg(internal::printf_precision_handler(), get_arg(it));
} else { } else {
spec.precision_ = 0; spec.precision_ = 0;
} }
} }
format_arg arg = get_arg(it, arg_index); 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); spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
if (spec.fill_ == '0') { if (spec.fill_ == '0') {
if (arg.is_arithmetic()) if (arg.is_arithmetic())
...@@ -551,7 +551,8 @@ void basic_printf_context<OutputIt, Char, AF>::format() { ...@@ -551,7 +551,8 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
break; break;
case 'c': case 'c':
// TODO: handle wchar_t better? // 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; break;
} }
} }
...@@ -559,7 +560,7 @@ void basic_printf_context<OutputIt, Char, AF>::format() { ...@@ -559,7 +560,7 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
start = it; start = it;
// Format argument. // 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)); buffer.append(pointer_from(start), pointer_from(it));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment