Namespaces
Variants

推导指引用于 std::tuple

从 zh.cppreference.net
 
 
 
 
定义于头文件 <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}; // 此情况下使用了显式推导指南
}