Skip to content

Commit

Permalink
Add args() accessor back to fmt::format_context (#4310)
Browse files Browse the repository at this point in the history
Add args() accessor back to fmt::format_context
Add test that would fail to compile if you can't create a fmt::format_context from another fmt::format_context
  • Loading branch information
Erroneous1 authored Jan 17, 2025
1 parent 01914f0 commit 937b7c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,7 @@ class context {
FMT_CONSTEXPR auto arg_id(string_view name) const -> int {
return args_.get_id(name);
}
auto args() const -> const format_args& { return args_; }

// Returns an iterator to the beginning of the output range.
FMT_CONSTEXPR auto out() const -> iterator { return out_; }
Expand Down
9 changes: 9 additions & 0 deletions test/base-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,3 +875,12 @@ TEST(base_test, no_repeated_format_string_conversions) {
fmt::format_to(buf, nondeterministic_format_string());
#endif
}

TEST(base_test, format_context_accessors) {
class copier {
static fmt::format_context copy(fmt::appender app,
const fmt::format_context& ctx) {
return fmt::format_context(std::move(app), ctx.args(), ctx.locale());
}
};
}

0 comments on commit 937b7c5

Please sign in to comment.