Skip to content

Commit

Permalink
Add args() accessor back to fmt::format_context
Browse files Browse the repository at this point in the history
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 committed Jan 15, 2025
1 parent 01914f0 commit 30f8834
Show file tree
Hide file tree
Showing 2 changed files with 8 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
7 changes: 7 additions & 0 deletions test/compile-error-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,12 @@ if (CMAKE_CXX_STANDARD GREATER_EQUAL 20)
" ERROR)
endif ()

# Copying a format_context
expect_compile(format-context-accessors "
auto copy_context = [](fmt::appender app, const fmt::format_context& ctx)
-> fmt::format_context
{ return fmt::format_context(std::move(app), ctx.args(), ctx.locale()); };
")

# Run all tests
run_tests()

0 comments on commit 30f8834

Please sign in to comment.