std::tuple の推論補助
From cppreference.com
| ヘッダ <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}; // explicit deduction guide is used in this case }