example4_structured_bindings_with_tuple.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <iostream>
#include <tuple>

std::tuple<int, double, std::string> getPersonInfo() {
    return std::make_tuple(25, 180.5, "John Doe");
}

int main() {
    // Structured binding to unpack the tuple
    auto [age, height, name] = getPersonInfo();

    std::cout << "Age: " << age << std::endl;
    std::cout << "Height: " << height << std::endl;
    std::cout << "Name: " << name << std::endl;

    return 0;
}
Back to std_tuple