Skip to content

Commit f9afc16

Browse files
cycloawaodorincycloawaodorinakinomyoga
authored
P2905R2 により,make_format_args は左辺値しか受け取らないため,コンパイルエラーとなっていた例を修正 (#1595)
* P2905R2 により,make_format_args は左辺値しか受け取らないため,コンパイルエラーとなっていた例を修正 * Update reference/format/vformat.md Co-authored-by: Koichi Murase <myoga.murase@gmail.com> * P2905R2 に関する簡単な説明を追加 --------- Co-authored-by: cycloawaodorin <cycloawaodorin@gmail.com> Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
1 parent 23af864 commit f9afc16

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

reference/format/make_format_args.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
namespace std {
1010
template<class Context = format_context, class... Args>
1111
format_arg_store<Context, Args...>
12-
make_format_args(Args&&... args); // (1) C++20
12+
make_format_args(Args&... args); // (1) C++20
1313
template<class Context = format_context, class... Args>
1414
constexpr format_arg_store<Context, Args...>
15-
make_format_args(Args&&... args); // (1) C++26
15+
make_format_args(Args&... args); // (1) C++26
1616

1717
template<class... Args>
1818
format_arg_store<wformat_context, Args...>
19-
make_wformat_args(Args&&... args); // (2) C++20
19+
make_wformat_args(Args&... args); // (2) C++20
2020
template<class... Args>
2121
constexpr format_arg_store<wformat_context, Args...>
22-
make_wformat_args(Args&&... args); // (2) C++26
22+
make_wformat_args(Args&... args); // (2) C++26
2323
}
2424
```
2525
* format_arg_store[italic]
@@ -79,7 +79,8 @@ return make_format_args<wformat_context>(args...);
7979

8080
int main() {
8181
std::string fmt = "0x{:x} 0b{:04b}";
82-
std::string s = std::vformat(fmt, std::make_format_args(10, 6));
82+
int m = 10, n = 6;
83+
std::string s = std::vformat(fmt, std::make_format_args(m, n));
8384
std::cout << s << std::endl;
8485
}
8586
```
@@ -124,3 +125,5 @@ namespace std {
124125
125126
* [P0645R10 Text Formatting](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html)
126127
* [P2418R2 Add support for `std::generator`-like types to `std::format`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2418r2.html)
128+
* [P2905R2 Runtime format strings](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2905r2.html)
129+
* C++23 発効後の DR として、引数を非 `const` 左辺値参照とすることで、一時オブジェクトを渡すことによる寿命切れオブジェクトの参照を回避する変更が提案された。これは C++20 まで遡及適用された。

reference/format/vformat.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ C++26以降は、実行時文字列のフォーマット引数を使用したい
7070
7171
int main() {
7272
std::string fmt = "0x{:x} 0b{:04b}";
73-
std::string s = std::vformat(fmt, std::make_format_args(10, 6));
73+
int m = 10, n = 6;
74+
std::string s = std::vformat(fmt, std::make_format_args(m, n));
7475
std::cout << s << std::endl;
7576
}
7677
```
@@ -132,5 +133,6 @@ string vformat(const locale& loc, wstring_view fmt, wformat_args args) {
132133
133134
- [Working Draft, Standard for Programming Language C++ [format]](https://timsong-cpp.github.io/cppwp/format)
134135
- [P0645R10 Text Formatting](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html)
136+
- [P2905R2 Runtime format strings](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2905r2.html)
135137
- [P3391R2 `constexpr std::format`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3391r2.html)
136138
- C++26から非ロケール版が`constexpr`に対応した

0 commit comments

Comments
 (0)