C++ std__get(std__tuple)

https://en.cppreference.com/w/cpp/utility/tuple/get
the type T in std::get must occur exactly once in the tuple.

cpp 复制代码
#include <iostream>
#include <string>
#include <tuple>

int main()
{
    auto t = std::make_tuple(1, "Foo", 3.14);
    // index-based access
    std::cout << "(" << std::get<0>(t) << ", " << std::get<1>(t)
        << ", " << std::get<2>(t) << ")\n";
    // type-based access (C++14 or later), the type T in std::get<T> must occur exactly once in the tuple
    std::cout << "(" << std::get<int>(t) << ", " << std::get<const char*>(t)
        << ", " << std::get<double>(t) << ")\n";
    // Note: std::tie and structured binding may also be used to decompose a tuple
}
相关推荐
unicrom_深圳市由你创科技16 小时前
哪些控制逻辑应该放在 PLC,哪些放在上位机?
c++
玖玥拾18 小时前
C/C++ 基础笔记(十三)继承
c语言·c++·继承
ao-weilai19 小时前
C++:哈希表
c++·哈希算法·散列表
汉克老师19 小时前
GESP7级C++考试语法知识(二、指数函数(1、pow() 函数)
c++·指数函数·pow·gesp7级·精度误差
旖-旎19 小时前
FloodFill(图像渲染)(1)
c++·算法·深度优先·力扣
汉克老师20 小时前
GESP2026年3月认证C++六级真题与解析(编程题1 选数)
c++·动态规划·线性dp·gesp六级·状态转移·选与不选
有点。20 小时前
C++倍增法(练习题)
c++·算法
凡人叶枫20 小时前
Effective C++ 条款23:宁以 non-member、non-friend 替换 member 函数
linux·开发语言·c++·嵌入式开发
C语言小火车21 小时前
什么时候用智能指针?什么时候用裸指针?
c语言·c++·学习·指针
玖玥拾21 小时前
C/C++ 基础笔记(十二)友元、运算符重载
c语言·c++·运算符重载·友元