On Fri, Jun 27, 2014 at 06:04:18AM +0000, Uranuz via Digitalmars-d-learn wrote: > Compiler can't deduce type for template struct Pair when using it with > enum argument. There is an example > > import std.stdio; > > enum Category { first, second, third }; > > struct Pair(F, S) > { > F first; > S second; > > this(F f, S s) > { > first = f; > second = s; > } > } > > > void main() > { > auto p = Pair(Category.first, "first"); //It fails > > writeln(p); > } > > Is it not working for some reason or I'm doing something wrong or is > it just lack of implementation? How I could make this working without > explicit specifying of types?
Try this: struct Pair(F, S) { F first; S second; } auto pair(F,S)(F f, S s) { return Pair!(F,S)(f,s); } void main() { auto p = pair(Category.first, "first"); } T -- Don't throw out the baby with the bathwater. Use your hands...