diff --git a/include/fmt/args.h b/include/fmt/args.h index 6ed30c0bd5c0..3ff47880748f 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -210,6 +210,9 @@ template class dynamic_format_arg_store { data_.reserve(new_cap); named_info_.reserve(new_cap_named); } + + /// Returns the number of elements in the store. + size_t size() const noexcept { return data_.size(); } }; FMT_END_NAMESPACE diff --git a/test/args-test.cc b/test/args-test.cc index f99ff74ed192..e3efa244bfb7 100644 --- a/test/args-test.cc +++ b/test/args-test.cc @@ -186,3 +186,17 @@ TEST(args_test, move_constructor) { store.reset(); EXPECT_EQ(fmt::vformat("{} {} {a1}", moved_store), "42 foo foo"); } + +TEST(args_test, size) { + fmt::dynamic_format_arg_store store; + EXPECT_EQ(store.size(), 0); + + store.push_back(42); + EXPECT_EQ(store.size(), 1); + + store.push_back("Molybdenum"); + EXPECT_EQ(store.size(), 2); + + store.clear(); + EXPECT_EQ(store.size(), 0); +}