On Wednesday, 23 April 2014 at 00:02:29 UTC, Jesse Phillips wrote:
On Tuesday, 22 April 2014 at 07:54:34 UTC, Matthew Dudley wrote:
Here's the gist of what I'm trying to do.
https://gist.github.com/pontifechs/11169069
I'm getting an error I don't understand:
tinker.d(42): Error: mismatched function return type inference
of tinker.B and tinker.A
tinker.d(55): Error: template instance tinker.DynamicTuple!(A,
B).DynamicTuple.notopDispatch!"one" error instantiating
Failed: 'dmd' '-v' '-o-' 'tinker.d' '-I.'
Also, as an aside, why can't tuples be indexed dynamically?
Most of my problems with this have been because you apparently
can't.
Might have this a little bit wrong, just a quick hand
translation of:
foreach (i, elem; tuple)
if (names[i] == s)
{
return elem;
}
This becomes something like:
if (names[0] == "one")
return A;
if (names[1] == "one")
return B;
As said I could have this mixed up, but /elem/ is a type. But
even if they were an object, you are saying that this method
may return an A or a B, it is not legal for a function to
return different types.
I'd suggest a static if, but since /names/ is dynamic, that
won't work.
tuple in this case would be the member variable of type T (from
T...) So wouldn't elem be the actual object, and not the type?
The effective lowering I was hoping for would be something like
this
if (names[0] == "one")
return tuple[0];
if (names[1] == "one")
return tuple[1];
etc...