I was thinking it would be handy if tuples had a way to access a field
by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
The get method takes the field name and the type of the presumed field,
and it returns the value
On 10/16/16 3:58 PM, Andrei Alexandrescu wrote:
I was thinking it would be handy if tuples had a way to access a field
by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
I swear I've seen a pull request merged that add
On 10/16/2016 11:07 AM, Dmitry Olshansky wrote:
On 10/16/16 3:58 PM, Andrei Alexandrescu wrote:
I was thinking it would be handy if tuples had a way to access a field
by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu
wrote:
I was thinking it would be handy if tuples had a way to access
a field by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
That would mean that tup
On Sun, 16 Oct 2016 18:51:06 +, Sebastiaan Koppe wrote:
> On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu wrote:
>> I was thinking it would be handy if tuples had a way to access a field
>> by name at runtime. E.g.:
>>
>> Tuple!(int, "a", double, "b") t;
>> string x = condition
On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu
wrote:
I was thinking it would be handy if tuples had a way to access
a field by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
The get method takes the
On Sunday, 16 October 2016 at 20:11:01 UTC, Chris Wright wrote:
On Sun, 16 Oct 2016 18:51:06 +, Sebastiaan Koppe wrote:
On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei
Alexandrescu wrote:
I was thinking it would be handy if tuples had a way to
access a field by name at runtime. E.g.:
On Sunday, 16 October 2016 at 18:51:06 UTC, Sebastiaan Koppe
wrote:
On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu
wrote:
I was thinking it would be handy if tuples had a way to access
a field by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a
On Sunday, 16 October 2016 at 20:11:01 UTC, Chris Wright wrote:
On Sun, 16 Oct 2016 18:51:06 +, Sebastiaan Koppe wrote:
That would mean that tuple then needs to keep the strings
around - taking up space.
It doesn't change Tuple.sizeof.
Sure, but it still takes up space in the executable.
On Sunday, 16 October 2016 at 16:49:43 UTC, Andrei Alexandrescu
wrote:
Sadly it was closed, not merged. And it was a bit more general
allowing getting a field by name from any struct. -- Andrei
The PR in question if anyone is interested:
https://github.com/dlang/phobos/pull/4154
I currently
On 10/16/16 9:58 AM, Andrei Alexandrescu wrote:
I was thinking it would be handy if tuples had a way to access a field
by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
The get method takes the field name and the type
On Monday, 17 October 2016 at 13:35:12 UTC, Steven Schveighoffer
wrote:
Why not something like this:
Val get(T, Val)(auto ref T item, string memberName, Val
defaultValue)
{
switch(memberName)
{
foreach(n; __traits(allMembers, T))
{
static if(is(typeof(__traits(getMember, ite
On 10/17/16 9:42 AM, Edwin van Leeuwen wrote:
On Monday, 17 October 2016 at 13:35:12 UTC, Steven Schveighoffer wrote:
Why not something like this:
Val get(T, Val)(auto ref T item, string memberName, Val defaultValue)
{
switch(memberName)
{
foreach(n; __traits(allMembers, T))
{
On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu
wrote:
I was thinking it would be handy if tuples had a way to access
a field by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
In Scala you can do this:
def getUserInfo = ("Al", 42, 20
On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu
wrote:
I was thinking it would be handy if tuples had a way to access
a field by name at runtime. E.g.:
Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);
The get method takes the
15 matches
Mail list logo