Clarifying What A Tuple is in C++

Hi all,

I apologise if this question is a bit pedantic, but I've been struggling with this all day and the more research I do the more conflicting and vague information I find.

I understand that in Maths a Tuple is an ordered list but most of the definitions I've seen for a Tuple in C++ describe it as an object or a data object??. I'm confused by what that term means concerning structs and classes, which I've understood to be the blueprint/cookie-cutter of objects. My understanding was tuples are an ADT which in the same way as classes allows the user to create a custom-composite data TYPE??? But I feel like I'm missing something. It feels like Tuples sit somewhere in-between Structs and Arrays conceptually.

If I wrote a sentence along the lines of.....
" A Tuple is a composite data type defined by the user which allows the grouping of different data members within it"..... would I be incorrect?
Are Tuples an Abstract Data Type or an Abstract Data Object? Can you create instances of type Tuple after it's been declared?

I am humbly grateful for any help and clarification.
its a container in c++. Like the word vector, the concept is only tangentially tied to the math definition.

Its almost like a C-struct type thing -- a heterogeneous grouping of variables (or their types, if you think that way). This is the closest thing I can offer to relate it to, is a 'methodless struct' from C. Remember that c++ structs are the same as c++ classes, though, apart from default public vs default private.

" A Tuple is a composite data type defined by the user which allows the grouping of different data members within it"..... would I be incorrect?

^^ that seems correct.


Are Tuples an Abstract Data Type or an Abstract Data Object? Can you create instances of type Tuple after it's been declared?

Yes, you can make more of them as a type. The example in our reference shows doing that using auto to mask the complexity.

I don't recall what makes a type abstract. I will offer 'yes', its an ADT, but I honestly forget the book/school technical terms as I have not seen in decades.

Honestly I always end up making a full struct for 'micro classes'. The few times I started with a tuple I ended up with a struct re-do because I wanted a little more. If you can add more stuff to a tuple, I don't know exactly how, but I didn't fight it since it seems redundant. The gurus can fill in on this a bit maybe... when to use it vs a struct.. The most useful thing I have seen done with one is to bundle a few unrelated things as a return type from a function where normally the bundled things are not tied together into any kind of construct, its just for the ease of passing it?
Last edited on
As always Jonnin I am hugely grateful. You're my MVP!
Topic archived. No new replies allowed.