Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow getting size of dynamic format arg store #4270

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ template <typename Context> 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
Expand Down
14 changes: 14 additions & 0 deletions test/args-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<fmt::format_context> 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);
}
Loading