std::tuple 的推导指引
来自cppreference.com
工具库
std::tuple
| 成员函数 | ||||
| 非成员函数 | ||||
|
(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20)
|
||||
| 推导指引(C++17) | ||||
| 辅助概念 | ||||
|
(C++23)
|
||||
| 辅助类 | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
在标头
<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}; // 用于此场合的显式推导指引 }