C++C++17Code SnippetLearn C++Templates

Learn To Use std::tuple In A C++ Compiler For Windows

What is a tuple, or std::tuple? How can I use a tuple in a C++ compiler? Can I store different types of variables in tuple template?

What does std::tuple mean to a C++ compiler?

The tuple ( std::tuple) is a class template a fixed-size collection of different types of values like floats, integers, texts, etc. In another term tuple stores the different types of the elements, it also supports empty lists. This template is available since C++11 and improved in C++20 standards.

std::tuple is a generalization of std::pair. The destructor of tuple is trivial if std::is_trivially_destructible<type>::value is set to true for every type in Types.

What is the syntax for the C++ std::tuple?

Here is the syntax of std::tuple:

Is there a std::tuple example I can use in my Windows C++ compiler?

Here is a example to define different types of members in a my_tuple,

As in this example we can print out each element by using std::get< > as given example below,

And the output will be,

How to iterate std::tuple?

Interestingly std::tuple has no begin() and end() iterator parameters, that means you cannot iterate in a C++ compiler of version C++17 and before. To Iterate on std::tuple you can use std::apply as below,

And the output will be,


C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.


Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++Syntax

What Is Deleted Implicitly-declared Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What Is A Forced (Default) Copy Assignment Operator In Modern C++

C++C++11C++14C++17C++20Learn C++Syntax

What is Implicitly-declared Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What is Avoiding Implicit Copy Assignment In C++?