tuple元组(C++11及以后,如C++14)
类tuple与array最本质的区别当数tuple元组元素类型可以不一样,而统一数组array的元素类型必须一样。
本文主要举例:
tuple_size
Example
|
|
Output:
foo contains: 100 y |
tie----(unpack)
Example
|
|
Output:
myint contains: 10 mychar contains: a |
std:tuple_element
Member types
member type | definition |
---|---|
type | The Ith type in the tuple object |
Example
|
|
Output:
mytuple contains: 10 and a |
tuple_size
Member constants
member constant | definition |
---|---|
value | The number of elements in the tuple or tuple-like object. This is a constexpr value of the unsigned integral type size_t. |
Example
|
|
Output:
mytuple has 3 elements |
forward_as_tuple
Parameters
- args
- List of elements to be forwarded as a tuple object of references.
Return Value
A tuple object with rvalue references to args suitable to be forwarded as argument to a function.
Example
|
|
Output:
John Smith, 25 John Daniels, 22 |
tuple_cat
Parameters
- tpls
- Comma-separated list of tuple objects. These may be of different types.
Return Value
A tuple object of the appropriate type to hold args.
The type of the returned object (tuple<CTypes...>
) is the tuple type that contains the ordered sequence of all the extended types inTuples.
Example
|
|
Output:
myauto contains: 3.14 pi 10 a |
ignore tie
Parameters
- args
- List of objects (lvalues) to be tied as elements of a tuple.
Return Value
A tuple with lvalue references to args.
Example
|
|
Output:
myint contains: 10 mychar contains: a |
标签:
tuple C++
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!