Allow mixing named and automatic arguments

This commit is contained in:
Victor Zverovich 2017-12-09 08:15:13 -08:00
parent 7cea163809
commit 971fb584c3
2 changed files with 5 additions and 6 deletions

View File

@ -3001,12 +3001,10 @@ struct dynamic_formatter {
template <typename Char>
inline typename basic_context<Char>::format_arg
basic_context<Char>::get_arg(basic_string_view<Char> name) {
if (this->check_no_auto_index()) {
map_.init(this->args());
if (const format_arg *arg = map_.find(name))
return *arg;
this->on_error("argument not found");
}
map_.init(this->args());
if (const format_arg *arg = map_.find(name))
return *arg;
this->on_error("argument not found");
return format_arg();
}

View File

@ -488,6 +488,7 @@ TEST(FormatterTest, NamedArg) {
EXPECT_THROW_MSG(format("{a}"), format_error, "argument not found");
EXPECT_EQ(" -42", format("{0:{width}}", -42, fmt::arg("width", 4)));
EXPECT_EQ("st", format("{0:.{precision}}", "str", fmt::arg("precision", 2)));
EXPECT_EQ("1 2", format("{} {two}", 1, fmt::arg("two", 2)));
}
TEST(FormatterTest, AutoArgIndex) {