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

How To Use Tuple Addressing Via Type In C++14 And Beyond

How To Use Tuple Addressing Via Type In C++14 And Beyond

The tuple ( std::tuple ) is a class template that stores the different types of elements, it also supports empty lists in modern C++. This template was introduced in C++11 and improved in C++14. In this post, we explain tuple addressing via type features that come with the C++14 standard.

What is std::tuple in C++?

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

In C++ programming, the std::tuple is a generalization of std::pair. The destructor of the tuple is trivial if std::is_trivially_destructible::value is set to true for every type in Types.

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

Here is the syntax of std::tuple in C++,

Is there a C++ std::tuple example, how can we use tuples?

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

How to use tuple addressing via type feature in C++14 and beyond?

The std::tuple type introduced in C++11 and improved in C++14 extends with the tuple addressing by type feature that allows fetching from a tuple by type instead of by index. 

Here are the new std::get templates defined in the <tuple> header of C++14 and beyond,

Is there a simple tuple addressing via type example in C++14 and beyond?

Here is a simple example that shows we can get the value of an int type from tuple.

Is there a full example about the tuple addressing by type in C++14 and beyond?

Here is a full example about the tuple addressing by type in C++14 and beyond,

Here is the output.

Note that, if the tuple has more than one same element of the type, a compile-time error results.

How To Use Tuple Addressing Via Type In C++14 And Beyond the C++ Builder Logo

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 graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17C++20Learn C++NumericsSyntax

How To Compute The Greatest Common Divisor And Least Common Multiple in C++?

C++C++17Language FeatureLearn C++

How To Use Skia Shader SkSL Shading Language Code in C++ Builder?

Artificial Intelligence TechC++C++17C++20Learn C++

How To Create Simple Generative AI Code In C++

C++C++17Language FeatureLearn C++

How To Use The SVG Image Format With Skia In C++ Builder