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};// 用于此场合的显式推导指引}
close