Skip to content

Commit 49f50b7

Browse files
committed
basic_format_arg/op_constructorの説明を追加
1 parent 98c71c6 commit 49f50b7

File tree

3 files changed

+120
-80
lines changed

3 files changed

+120
-80
lines changed

reference/format/basic_format_arg.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,31 @@
77
```cpp
88
namespace std {
99
template<class Context>
10-
class basic_format_arg;
10+
class basic_format_arg {
11+
public:
12+
class handle;
13+
14+
private:
15+
using char_type = typename Context::char_type; // exposition only
16+
17+
variant<monostate, bool, char_type,
18+
int, unsigned int, long long int, unsigned long long int,
19+
float, double, long double,
20+
const char_type*, basic_string_view<char_type>,
21+
const void*, handle> value; // exposition only
22+
23+
template<class T> explicit basic_format_arg(T& v) noexcept; // exposition only
24+
25+
public:
26+
basic_format_arg() noexcept;
27+
28+
explicit operator bool() const noexcept;
29+
30+
template<class Visitor>
31+
decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
32+
template<class R, class Visitor>
33+
R visit(this basic_format_arg arg, Visitor&& vis);
34+
};
1135
}
1236
```
1337
@@ -26,7 +50,7 @@ namespace std {
2650
2751
| 名前 | 説明 | 対応バージョン |
2852
|-----------------|----------------|----------------|
29-
| `(constructor)` | コンストラクタ | C++20 |
53+
| [`(constructor)`](basic_format_arg/op_constructor.md) | コンストラクタ | C++20 |
3054
3155
### 変換演算子
3256
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# コンストラクタ
2+
3+
* format[meta header]
4+
* function[meta id-type]
5+
* std[meta namespace]
6+
* basic_format_arg[meta class]
7+
* cpp20[meta cpp]
8+
9+
```cpp
10+
namespace std {
11+
template<class Context>
12+
class basic_format_arg {
13+
private:
14+
using char_type = typename Context::char_type; // exposition only
15+
16+
variant<monostate, bool, char_type,
17+
int, unsigned int, long long int, unsigned long long int,
18+
float, double, long double,
19+
const char_type*, basic_string_view<char_type>,
20+
const void*, handle> value; // exposition only
21+
22+
template<class T> explicit basic_format_arg(T& v) noexcept; // (2) exposition only
23+
24+
public:
25+
basic_format_arg() noexcept; // (1)
26+
};
27+
}
28+
```
29+
* varialt[link /reference/varialt/varialt.md]
30+
* monostate[link /reference/varialt/monostate.md]
31+
* basic_string_view[link /reference/string_view/basic_string_view.md]
32+
* handle[link handle.md]
33+
* basic_format_arg[italic]
34+
35+
## 概要
36+
37+
* (1): 空の`basic_format_arg`を構築する
38+
* (2): (説明専用)[`make_format_args`](../make_format_args.md)の内部で使用され、引数から`basic_format_args`を構築する。
39+
40+
## テンプレートパラメーター制約
41+
42+
- (2):
43+
- `T`はフォーマットできる型であること
44+
45+
## 事前条件
46+
47+
- (2): もし `decay_t<T>` が `char_type*` または `const char_type*` である場合、 `static_cast<const char_type*>(v)` はヌル終端された `char_type` の配列を指すこと。
48+
49+
## 事後条件
50+
51+
- (1): `!(*this)`
52+
53+
## 例外
54+
55+
投げない。
56+
57+
## 効果
58+
59+
- (1): `value`を[`monostate`](/reference/varialt/monostate.md)で初期化する。
60+
61+
- (2): `TD`を`remove_const<T>`として、以下の順に`value`を初期化する。
62+
- `TD`が`bool`なら、`v`で初期化
63+
- `TD`が`char`かつ`char_type`が`wchar_t`なら、`value`を`static_cast<wchar_t>(v)`で初期化
64+
- `TD`が`char`かつ`char_type`が`wchar_t`なら、`value`を`static_cast<wchar_t>(static_cast<unsigned char>(v))`で初期化
65+
- `TD`が符号つき整数型かつ`sizeof(TD) <= sizeof(int)`なら、`value`を`static_cast<int>(v)`で初期化
66+
- `TD`が符号なし整数型かつ`sizeof(TD) <= sizeof(unsigned int)`なら、`value`を`static_cast<unsigned int>(v)`で初期化
67+
- `TD`が符号つき整数型かつ`sizeof(TD) <= sizeof(long long int)`なら、`value`を`static_cast<long long int>(v)`で初期化
68+
- `TD`が符号なし整数型かつ`sizeof(TD) <= sizeof(unsigned long long int)`なら、`value`を`static_cast<unsigned long long int>(v)`で初期化
69+
- `TD`が浮動小数点数なら、`v`で初期化
70+
- `TD`が`basic_string_view`または`basic_string`の特殊化で、`TD::value_type`が`char_type`と等しければ、`value`を`basic_string_view<char_type>(v.data(), v.size())`で初期化
71+
- `decay_t<T>`が`char_type*`または `const char_type*` なら、`value`を`static_cast<const char_type*>(v)`で初期化
72+
- `is_void_v<remove_pointer_t<TD>>`が`true`、または`is_null_pointer_v<TD>`が`true`なら、`value`を`static_cast<const void*>(v)`で初期化
73+
- それ以外なら、`value`を`handle(v)`で初期化
74+
75+
## バージョン
76+
### 言語
77+
- C++20
78+
79+
### 処理系
80+
- [Clang](/implementation.md#clang): ??
81+
- [GCC](/implementation.md#gcc): ??
82+
- [ICC](/implementation.md#icc): ??
83+
- [Visual C++](/implementation.md#visual_cpp): ??
84+
85+
## 参照
86+
87+
* [P0645R10 Text Formatting](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html)

reference/format/make_format_args.md

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -47,92 +47,21 @@ string format(string_view fmt, const Args&... args)
4747
## 事前条件
4848
すべての引数の型`Ti`について`Context::formatter_type<Ti>`が`Formatter`要件を満たすこと。
4949
50-
## 効果
51-
52-
(2)は次と等しい。
53-
54-
```cpp
55-
return make_format_args<wformat_context>(args...);
56-
```
57-
* wformat_context[link /reference/format/basic_format_context.md]
50+
## 戻り値
5851
59-
(1)は次と等しい。
52+
### (1)
6053
6154
```cpp
6255
return {basic_format_arg<Context>(args)...}
6356
```
64-
* basic_format_arg[link /reference/format/basic_format_arg.md]
57+
* basic_format_arg[link /reference/format/basic_format_arg/op_constructor.md]
6558

66-
ただし、便宜上、[`basic_format_arg`](/reference/format/basic_format_arg.md)は次のprivateメンバを持つとする。
67-
(これらのprivateメンバは規格に含まれない)
59+
### (2)
6860

6961
```cpp
70-
namespace std {
71-
template<class Context>
72-
class basic_format_arg {
73-
public:
74-
class handle;
75-
76-
private:
77-
using charT = typename Context::char_type;
78-
79-
variant<monostate, bool, charT,
80-
int, unsigned int, long long int, unsigned long long int,
81-
float, double, long double,
82-
const charT*, basic_string_view<charT>,
83-
const void*, handle> value;
84-
85-
template<typename T> explicit basic_format_arg(const T& v) noexcept; // (a)
86-
explicit basic_format_arg(float n) noexcept; // (b)
87-
explicit basic_format_arg(double n) noexcept; // (c)
88-
explicit basic_format_arg(long double n) noexcept; // (d)
89-
explicit basic_format_arg(const charT* s); // (e)
90-
91-
template<class traits>
92-
explicit basic_format_arg(
93-
basic_string_view<charT, traits> s) noexcept; // (f)
94-
95-
template<class traits, class Allocator>
96-
explicit basic_format_arg(
97-
const basic_string<charT, traits, Allocator>& s) noexcept; // (g)
98-
99-
explicit basic_format_arg(nullptr_t) noexcept; // (h)
100-
101-
template<class T>
102-
explicit basic_format_arg(const T* p) noexcept; // (i)
103-
104-
template<class Ctx, class... Args>
105-
friend format_arg_store<Ctx, Args...>
106-
make_format_args(const Args&... args);
107-
};
108-
}
62+
return make_format_args<wformat_context>(args...);
10963
```
110-
* variant[link /reference/variant/variant.md]
111-
* monostate[link /reference/variant/monostate.md]
112-
* handle[link /reference/format/basic_format_arg/handle.md]
113-
* basic_string[link /reference/string/basic_string.md]
114-
* basic_string_view[link /reference/string_view/basic_string_view.md]
115-
* basic_format_arg[link /reference/format/basic_format_arg.md]
116-
117-
ここで、それぞれの効果は次と等しい。
118-
119-
* (a):
120-
* `T``bool`または`charT`なら、`value``v`で初期化
121-
* または、`T``char`かつ`charT``wchar_t`なら、`value``static_cast<wchar_t>(v)`で初期化
122-
* または、`T`が符号つき整数型かつ`sizeof(T) <= sizeof(int)`なら、`value``static_cast<int>(v)`で初期化
123-
* または、`T`が符号なし整数型かつ`sizeof(T) <= sizeof(unsigned int)`なら、`value``static_cast<unsigned int>(v)`で初期化
124-
* または、`T`が符号つき整数型かつ`sizeof(T) <= sizeof(long long int)`なら、`value``static_cast<long long int>(v)`で初期化
125-
* または、`T`が符号なし整数型かつ`sizeof(T) <= sizeof(unsigned long long int)`なら、`value``static_cast<unsigned long long int>(v)`で初期化
126-
* または、`value``handle(v)`で初期化
127-
* (b),(c),(d): `value``n`で初期化
128-
* (e): `value``s`で初期化 (`s`は有効なC文字列であること)
129-
* (f): `value``s`で初期化
130-
* (g): `value``basic_string_view<charT>(s.data(), s.size())`で初期化
131-
* (h): `value``static_cast<const void*>(nullptr)`で初期化
132-
* (i): `value``p`で初期化 (`is_void_v<T>``true`であること)
133-
134-
## 戻り値
135-
`{basic_format_arg<Context>(args)...}`
64+
* wformat_context[link /reference/format/basic_format_context.md]
13665

13766
## 実装例
13867
```cpp
@@ -150,7 +79,7 @@ namespace std {
15079
}
15180
}
15281
```
153-
* basic_format_arg[link /reference/format/basic_format_arg.md]
82+
* basic_format_arg[link /reference/format/basic_format_arg/op_constructor.md]
15483
* wformat_context[link /reference/format/basic_format_context.md]
15584
15685
## バージョン

0 commit comments

Comments
 (0)