Skip to content

Commit c55d9f2

Browse files
committed
add op_deduction_guide to flat_map. (#1078)
1 parent 90d1897 commit c55d9f2

File tree

4 files changed

+266
-2
lines changed

4 files changed

+266
-2
lines changed

reference/flat_map/flat_map.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace std {
149149
150150
| 名前 | 説明 | 対応バージョン |
151151
|---------------------------------------------|------------------------------------|-------|
152-
| [`(deduction_guide)`](flat_map/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++23 |
152+
| [`(deduction_guide)`](flat_map/op_deduction_guide.md) | クラステンプレートの推論補助 | C++23 |
153153
154154
155155
## その他
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# 推論補助
2+
* flat_map[meta header]
3+
* std[meta namespace]
4+
* flat_map[meta class]
5+
* cpp23[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
// 説明用の型
10+
template <class InputIterator>
11+
using iter_key_t = remove_const_t<typename iterator_traits<InputIterator>::value_type::first_type>;
12+
template <class InputIterator>
13+
using iter_val_t = typename iterator_traits<InputIterator>::value_type::second_type;
14+
template<ranges::input_range Range>
15+
using range_key_t = remove_const_t<typename ranges::range_value_t<Range>::first_type>;
16+
template<ranges::input_range Range>
17+
using range_val_t = typename ranges::range_value_t<Range>::second_type;
18+
template<class Allocator, class T>
19+
using alloc_rebind = typename allocator_traits<Allocator>::template rebind_alloc<T>;
20+
21+
template<class KeyContainer, class MappedContainer,
22+
class Compare = less<typename KeyContainer::value_type>>
23+
flat_map(KeyContainer, MappedContainer, Compare = Compare())
24+
-> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
25+
Compare, KeyContainer, MappedContainer>; // (1)
26+
27+
template<class KeyContainer, class MappedContainer, class Allocator>
28+
flat_map(KeyContainer, MappedContainer, Allocator)
29+
-> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
30+
less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>; // (2)
31+
32+
template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
33+
flat_map(KeyContainer, MappedContainer, Compare, Allocator)
34+
-> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
35+
Compare, KeyContainer, MappedContainer>; // (3)
36+
37+
template<class KeyContainer, class MappedContainer,
38+
class Compare = less<typename KeyContainer::value_type>>
39+
flat_map(sorted_unique_t, KeyContainer, MappedContainer, Compare = Compare())
40+
-> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
41+
Compare, KeyContainer, MappedContainer>; // (4)
42+
43+
template<class KeyContainer, class MappedContainer, class Allocator>
44+
flat_map(sorted_unique_t, KeyContainer, MappedContainer, Allocator)
45+
-> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
46+
less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>; // (5)
47+
48+
template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
49+
flat_map(sorted_unique_t, KeyContainer, MappedContainer, Compare, Allocator)
50+
-> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
51+
Compare, KeyContainer, MappedContainer>; // (6)
52+
53+
template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>>
54+
flat_map(InputIterator, InputIterator, Compare = Compare())
55+
-> flat_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare>; // (7)
56+
57+
template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>>
58+
flat_map(sorted_unique_t, InputIterator, InputIterator, Compare = Compare())
59+
-> flat_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare>; // (8)
60+
61+
template<ranges::input_range R, class Compare = less<range_key_t<R>>,
62+
class Allocator = allocator<byte>>
63+
flat_map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
64+
-> flat_map<range_key_t<R>, range_val_t<R>, Compare,
65+
vector<range_key_t<R>, alloc_rebind<Allocator, range_key_t<R>>>,
66+
vector<range_val_t<R>, alloc_rebind<Allocator, range_val_t<R>>>>; // (9)
67+
68+
template<ranges::input_range R, class Allocator>
69+
flat_map(from_range_t, R&&, Allocator)
70+
-> flat_map<range_key_t<R>, range_val_t<R>, less<range_key_t<R>>,
71+
vector<range_key_t<R>, alloc_rebind<Allocator, range_key_t<R>>>,
72+
vector<range_val_t<R>, alloc_rebind<Allocator, range_val_t<R>>>>; // (10)
73+
74+
template<class Key, class T, class Compare = less<Key>>
75+
flat_map(initializer_list<pair<Key, T>>, Compare = Compare())
76+
-> flat_map<Key, T, Compare>; // (11)
77+
78+
template<class Key, class T, class Compare = less<Key>>
79+
flat_map(sorted_unique_t, initializer_list<pair<Key, T>>, Compare = Compare())
80+
-> flat_map<Key, T, Compare>; // (12)
81+
```
82+
* vector[link /reference/vector/vector.md]
83+
* from_range_t[link ../../ranges/from_range_t.md]
84+
* sorted_unique_t[link ../sorted_unique_t.md]
85+
* remove_const_t[link /reference/type_traits/remove_const.md]
86+
* pair[link /reference/utility/pair.md]
87+
* iterator_traits[link /reference/iterator/iterator_traits.md]
88+
* less[link /reference/functional/less.md]
89+
* allocator[link /reference/memory/allocator.md]
90+
* initializer_list[link /reference/initializer_list/initializer_list.md]
91+
* ranges::input_range[link /reference/ranges/input_range.md]
92+
* allocator_traits[link /reference/memory/allocator_traits.md]
93+
* byte[link /reference/cstddef/byte.md]
94+
95+
96+
## 概要
97+
`std::flat_map`クラステンプレートの型推論補助。
98+
99+
- (1) : キーのコンテナ、値のコンテナ、比較関数からの推論
100+
- (2) : キーのコンテナ、値のコンテナ、アロケータからの推論
101+
- (3) : キーのコンテナ、値のコンテナ、比較関数、アロケータからの推論
102+
- (4) : キーのコンテナ、値のコンテナ、比較関数からの推論
103+
- (5) : キーのコンテナ、値のコンテナ、アロケータからの推論
104+
- (6) : キーのコンテナ、値のコンテナ、比較関数、アロケータからの推論
105+
- (7) : イテレータ範囲、比較関数からの推論
106+
- (8) : イテレータ範囲、比較関数からの推論
107+
- (9) : Range、比較関数、アロケータからの推論
108+
- (10) : Range、アロケータからの推論
109+
- (11) : 初期化子リスト、比較関数からの推論
110+
- (12) : 初期化子リスト、比較関数からの推論
111+
112+
113+
## 備考
114+
- C++23時点において、`flat_map`の推論補助は使いにくい。これはイテレータ範囲や組でのキーの型が`const Key`となっているためだ。この使いにくさは、将来の言語拡張で改良される可能性がある。
115+
```cpp
116+
flat_map m = {{1, 1}, {2, 2}, {3, 3}}; // コンパイルエラー! 初期化子リストからconst Keyを導出できない
117+
flat_map m2 = initializer_list<pair<const int, int>>({{1, 1}, {2, 2}, {3, 3}}); // OK
118+
```
119+
120+
121+
## バージョン
122+
### 言語
123+
- C++23
124+
125+
### 処理系
126+
- [Clang](/implementation.md#clang): ??
127+
- [GCC](/implementation.md#gcc): ??
128+
- [Visual C++](/implementation.md#visual_cpp): ??
129+
130+
131+
## 参照
132+
- [LWG Issue 3025. Map-like container deduction guides should use `pair<Key, T>`, not `pair<const Key, T>`](https://wg21.cmeerw.net/lwg/issue3025)

reference/flat_map/flat_multimap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace std {
145145
146146
| 名前 | 説明 | 対応バージョン |
147147
|---------------------------------------------|------------------------------------|-------|
148-
| [`(deduction_guide)`](flat_multimap/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++23 |
148+
| [`(deduction_guide)`](flat_multimap/op_deduction_guide.md) | クラステンプレートの推論補助 | C++23 |
149149
150150
151151
## その他
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# 推論補助
2+
* flat_map[meta header]
3+
* std[meta namespace]
4+
* flat_multimap[meta class]
5+
* cpp23[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
// 説明用の型
10+
template <class InputIterator>
11+
using iter_key_t = remove_const_t<typename iterator_traits<InputIterator>::value_type::first_type>;
12+
template <class InputIterator>
13+
using iter_val_t = typename iterator_traits<InputIterator>::value_type::second_type;
14+
template<ranges::input_range Range>
15+
using range_key_t = remove_const_t<typename ranges::range_value_t<Range>::first_type>;
16+
template<ranges::input_range Range>
17+
using range_val_t = typename ranges::range_value_t<Range>::second_type;
18+
template<class Allocator, class T>
19+
using alloc_rebind = typename allocator_traits<Allocator>::template rebind_alloc<T>;
20+
21+
template<class KeyContainer, class MappedContainer,
22+
class Compare = less<typename KeyContainer::value_type>>
23+
flat_multimap(KeyContainer, MappedContainer, Compare = Compare())
24+
-> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
25+
Compare, KeyContainer, MappedContainer>; // (1)
26+
27+
template<class KeyContainer, class MappedContainer, class Allocator>
28+
flat_multimap(KeyContainer, MappedContainer, Allocator)
29+
-> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
30+
less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>; // (2)
31+
32+
template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
33+
flat_multimap(KeyContainer, MappedContainer, Compare, Allocator)
34+
-> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
35+
Compare, KeyContainer, MappedContainer>; // (3)
36+
37+
template<class KeyContainer, class MappedContainer,
38+
class Compare = less<typename KeyContainer::value_type>>
39+
flat_multimap(sorted_equivalent_t, KeyContainer, MappedContainer, Compare = Compare())
40+
-> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
41+
Compare, KeyContainer, MappedContainer>; // (4)
42+
43+
template<class KeyContainer, class MappedContainer, class Allocator>
44+
flat_multimap(sorted_equivalent_t, KeyContainer, MappedContainer, Allocator)
45+
-> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
46+
less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>; // (5)
47+
48+
template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
49+
flat_multimap(sorted_equivalent_t, KeyContainer, MappedContainer, Compare, Allocator)
50+
-> flat_multimap<typename KeyContainer::value_type, typename MappedContainer::value_type,
51+
Compare, KeyContainer, MappedContainer>; // (6)
52+
53+
template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>>
54+
flat_multimap(InputIterator, InputIterator, Compare = Compare())
55+
-> flat_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare>; // (7)
56+
57+
template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>>
58+
flat_multimap(sorted_equivalent_t, InputIterator, InputIterator, Compare = Compare())
59+
-> flat_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare>; // (8)
60+
61+
template<ranges::input_range R, class Compare = less<range_key_t<R>>,
62+
class Allocator = allocator<byte>>
63+
flat_multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
64+
-> flat_multimap<range_key_t<R>, range_val_t<R>, Compare,
65+
vector<range_key_t<R>, alloc_rebind<Allocator, range_key_t<R>>>,
66+
vector<range_val_t<R>, alloc_rebind<Allocator, range_val_t<R>>>>; // (9)
67+
68+
template<ranges::input_range R, class Allocator>
69+
flat_multimap(from_range_t, R&&, Allocator)
70+
-> flat_multimap<range_key_t<R>, range_val_t<R>, less<range_key_t<R>>,
71+
vector<range_key_t<R>, alloc_rebind<Allocator, range_key_t<R>>>,
72+
vector<range_val_t<R>, alloc_rebind<Allocator, range_val_t<R>>>>; // (10)
73+
74+
template<class Key, class T, class Compare = less<Key>>
75+
flat_multimap(initializer_list<pair<Key, T>>, Compare = Compare())
76+
-> flat_multimap<Key, T, Compare>; // (11)
77+
78+
template<class Key, class T, class Compare = less<Key>>
79+
flat_multimap(sorted_equivalent_t, initializer_list<pair<Key, T>>, Compare = Compare())
80+
-> flat_multimap<Key, T, Compare>; // (12)
81+
```
82+
* vector[link /reference/vector/vector.md]
83+
* from_range_t[link ../../ranges/from_range_t.md]
84+
* sorted_equivalent_t[link ../sorted_equivalent_t.md]
85+
* remove_const_t[link /reference/type_traits/remove_const.md]
86+
* pair[link /reference/utility/pair.md]
87+
* iterator_traits[link /reference/iterator/iterator_traits.md]
88+
* less[link /reference/functional/less.md]
89+
* allocator[link /reference/memory/allocator.md]
90+
* initializer_list[link /reference/initializer_list/initializer_list.md]
91+
* ranges::input_range[link /reference/ranges/input_range.md]
92+
* allocator_traits[link /reference/memory/allocator_traits.md]
93+
* byte[link /reference/cstddef/byte.md]
94+
95+
96+
## 概要
97+
`std::flat_multimap`クラステンプレートの型推論補助。
98+
99+
- (1) : キーのコンテナ、値のコンテナ、比較関数からの推論
100+
- (2) : キーのコンテナ、値のコンテナ、アロケータからの推論
101+
- (3) : キーのコンテナ、値のコンテナ、比較関数、アロケータからの推論
102+
- (4) : キーのコンテナ、値のコンテナ、比較関数からの推論
103+
- (5) : キーのコンテナ、値のコンテナ、アロケータからの推論
104+
- (6) : キーのコンテナ、値のコンテナ、比較関数、アロケータからの推論
105+
- (7) : イテレータ範囲、比較関数からの推論
106+
- (8) : イテレータ範囲、比較関数からの推論
107+
- (9) : Range、比較関数、アロケータからの推論
108+
- (10) : Range、アロケータからの推論
109+
- (11) : 初期化子リスト、比較関数からの推論
110+
- (12) : 初期化子リスト、比較関数からの推論
111+
112+
113+
## 備考
114+
- C++23時点において、`flat_multimap`の推論補助は使いにくい。これはイテレータ範囲や組でのキーの型が`const Key`となっているためだ。この使いにくさは、将来の言語拡張で改良される可能性がある。
115+
```cpp
116+
flat_multimap m = {{1, 1}, {2, 2}, {3, 3}}; // コンパイルエラー! 初期化子リストからconst Keyを導出できない
117+
flat_multimap m2 = initializer_list<pair<const int, int>>({{1, 1}, {2, 2}, {3, 3}}); // OK
118+
```
119+
120+
121+
## バージョン
122+
### 言語
123+
- C++23
124+
125+
### 処理系
126+
- [Clang](/implementation.md#clang): ??
127+
- [GCC](/implementation.md#gcc): ??
128+
- [Visual C++](/implementation.md#visual_cpp): ??
129+
130+
131+
## 参照
132+
- [LWG Issue 3025. Map-like container deduction guides should use `pair<Key, T>`, not `pair<const Key, T>`](https://wg21.cmeerw.net/lwg/issue3025)

0 commit comments

Comments
 (0)