deduction guides for
std::tuple
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::tuple
| Member functions | ||||
| Non-member functions | ||||
|
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
| Helper concepts | ||||
|
(C++23)
|
||||
| Helper classes | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Deduction guides (C++17) |
|
ヘッダーで定義
<tuple>
|
||
|
template
<
class
...
UTypes
>
tuple ( UTypes... ) - > tuple < UTypes... > ; |
(1) | (C++17以降) |
|
template
<
class
T1,
class
T2
>
tuple ( std:: pair < T1, T2 > ) - > tuple < T1, T2 > ; |
(2) | (C++17以降) |
|
template
<
class
Alloc,
class
...
UTypes
>
tuple ( std:: allocator_arg_t , Alloc, UTypes... ) - > tuple < UTypes... > ; |
(3) | (C++17以降) |
|
template
<
class
Alloc,
class
T1,
class
T2
>
tuple ( std:: allocator_arg_t , Alloc, std:: pair < T1, T2 > ) - > tuple < T1, T2 > ; |
(4) | (C++17以降) |
|
template
<
class
Alloc,
class
...
UTypes
>
tuple ( std:: allocator_arg_t , Alloc, tuple < UTypes... > ) - > tuple < UTypes... > ; |
(5) | (C++17以降) |
これらの 推論ガイド は、 std::tuple に対して提供されており、暗黙の推論ガイドでは見逃されていたエッジケース、特に非コピー可能な引数と配列からポインタへの変換を考慮しています。
例
このコードを実行
#include <tuple> int main() { int a[2], b[3], c[4]; std::tuple t1{a, b, c}; // この場合、明示的なデダクションガイドが使用されます }