[Issue 13196] New: Infer struct/class template args from constructor args
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jul 23 22:39:55 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13196
Issue ID: 13196
Summary: Infer struct/class template args from constructor args
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: turkeyman at gmail.com
It would be really nice if struct/class template args could be inferred from
their constructors, just the same as function template args are inferred from
the runtime args.
struct S(T)
{
this(T t)
{
m = t;
}
T m;
}
int myThing;
auto s = S!(typeof(myThing))(myThing); // horrible!
auto s = S(myThing); // this is much nicer, but not supported
The error is:
Error: struct db.tools.delegatethunk.S cannot deduce function from argument
types !()(int), candidates are:
db.tools.delegatethunk.S(T)
It seems the compiler is already well aware there is only one possibly match.
These sorts of issues pay off in meta-heavy code when used alongside
non-template types.
I find my meta often gets overwhelmed by additional meta to check for and
handle edge cases like this.
--
More information about the Digitalmars-d-bugs
mailing list