Bug 9819 – Allow access to named tuple's names.

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-26T09:40:00Z
Last change time
2014-06-23T02:44:34Z
Keywords
industry
Assigned to
nobody
Creator
jcrapuchettes

Comments

Comment #0 by jcrapuchettes — 2013-03-26T09:40:25Z
Currently, the only way to access the field names inside a named tuple is to access the fieldSpecs alias, index a specific field, and then .stringof it. Example: --- auto t = Tuple!(int, "s", int, "d")(0, 1); enum e = t.fieldSpecs[0].stringof; pragma(msg, e); --- Prints: FieldSpec!(int, "s") I propose that the template FieldSpec be moved from the private section of the Tuple struct to the public section. This would allow for the field names to be accessed directly through the FieldSpec template. Example: --- auto t = Tuple!(int, "s", int, "d")(0, 1); enum e = t.fieldSpecs[0].name; pragma(msg, e); --- Prints: s
Comment #1 by justin — 2014-06-06T21:17:55Z
Comment #2 by github-bugzilla — 2014-06-23T02:44:33Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/8f1991447c09c73c30da18e687f2da31c87a0c0a Fix #9819: Allow access to named tuple's names Adds a `fieldNames` alias to `std.typecons.Tuple` to return the user-supplied names. The actual fields are in an expression tuple, so the user-supplied names are simply aliases, which previous to this PR, were not accessible. https://issues.dlang.org/show_bug.cgi?id=9819 Fix Issue 9819