On Thursday, 27 March 2014 at 17:42:24 UTC, Luís Marques wrote:
Could this be made to work?
struct S(T)
{
T x;
this(T x)
{
this.x = x;
}
}
void main()
{
int x = 42;
auto s = S(x); // fails to deduce T
}
Sure, it *could* work but I doubt it ever actually will.
Instead, why not pass the type directly?
auto s = S!(typeof(x))(x);?
I know it's a little more work and not very pretty but it should
solve the problem.
Or, if your constructors are simple enough, maybe something like
this would work
struct S(alias X)
{
this() { this.x = X; }
}
...
auto s = S!(x);