Tuples: tuple()
You will get to learn about tuples and the use of the tuple() function in this lesson.
Tuples
Tuples are for combining multiple type values to be used as a single object. They are implemented as a library feature by the Tuple
template from the std.typecons
module.
Tuple makes use of AliasSeq
from the std.meta
module for some of its operations.
Tuple and tuple()
Tuples are usually constructed by the convenience function tuple()
:
Press + to interact
import std.stdio;import std.typecons;void main() {auto t = tuple(42, "hello");writeln(t);}
The tuple call above constructs an object that consists of the int
value 42
and the string
value hello
. The output of the program includes the type of the tuple object and its members.
The tuple type above is the equivalent of ...