名稱空間
變體
操作

std::tuple 的推導指南

來自 cppreference.com
< cpp‎ | utility‎ | tuple
 
 
 
 
定義於標頭檔案 <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
}