Tuple basics
Benji Smith
dlanguage at benjismith.net
Sat Sep 13 00:19:49 PDT 2008
Sam Hu wrote:
> Hi,
>
> I seached questions regarding Tuple in this newsgroup but did not find the the same question I have.Since I am a newbie ,they are too advanced to me at this moment.My question is just :What is tuple?what can tuple do in D while other languae like c++ can not do or can not do well?Could somebody please post a very simple code segment and an simple but enough explanation so that I can understand what the hell a tuple is .
>
> Thank,
> Sam
The way I understand it (which could be totally wrong; others can
correct me) is that a tuple is basically just an anonymous struct, at
least, from an implementation standpoint.
The fancy thing about tuples (which differentiates them from other
structs) is that you can create a tuple of types, and evaluate the
contents of that tuple at compile-time, within template declarations.
One important thing to keep in mind is that you *can't* return a tuple
from a function:
public Tuple!(int, int) myFunction() {
...
}
(At least, I think that's true. But again, I could be wrong.)
--benji
More information about the Digitalmars-d-learn
mailing list