Namespaces
Variants

deduction guides for std::tuple

From cppreference.net
Utilities library
ヘッダーで定義 <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}; // この場合、明示的なデダクションガイドが使用されます
}