[Issue 4666] New: Optional name for std.typecons.Tuples?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 17 07:31:15 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4666
Summary: Optional name for std.typecons.Tuples?
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-08-17 07:31:10 PDT ---
This correct D2 program:
import std.stdio: writeln;
import std.typecons: Tuple;
void main() {
alias Tuple!(double, "x", double, "y") Point2D;
writeln(Point2D());
}
Prints (DMD 2.048):
Tuple!(double,"x",double,"y")(nan, nan)
In recent versions of the Python std lib there is collections.namedtuple, that
is similar to std.typecons.Tuple:
http://docs.python.org/dev/library/collections.html#collections.namedtuple
A namedtuple contains a name too, this is handy when they get printed.
So in theory a Tuple may allow an optional name too:
import std.stdio: writeln;
import std.typecons: Tuple;
void main() {
alias Tuple!("Point2D", double, "x", double, "y") Point2D;
writeln(Point2D());
}
That may print:
Point2D(nan, nan)
The main difference between the Tuple named 'Point2D' and a normal struct named
'Point2D' is the extra features Tuples have (and will have) over plain structs.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list