Bug 9324 – Can't assign a type with a Tuple subtype to a Tuple
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-15T18:37:00Z
Last change time
2016-08-27T22:59:35Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-01-15T18:37:31Z
import std.string;
import std.typecons;
struct MyTuple(T...)
{
this(T args)
{
tup = Tuple!T(args);
}
void opAssign(Tuple!T args)
{
this.tup = args;
}
Tuple!T tup;
alias tup this;
}
void main()
{
MyTuple!(string, int) x;
x = tuple("foo", 1); // ok
Tuple!(string, int) y;
y = x; // fail
}
test.d(28): Error: template std.typecons.Tuple!(string, int).Tuple.opAssign does not match any function template declaration.
isTuple check fails on MyTuple even though it has a Tuple subtype. But why?
isTuple implementation:
template isTuple(T)
{
static if (is(Unqual!T Unused : Tuple!Specs, Specs...))
{
enum isTuple = true;
}
else
{
enum isTuple = false;
}
}
It seems to me like we need some way of determining if type 'A' has subtype 'B'. I don't think we have a trait or Phobos function to do it, perhaps we should introduce something like this?
Comment #1 by andrej.mitrovich — 2016-08-27T22:59:35Z