Partial ordering of constructors with type parameters
Charles McAnany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 23 09:44:35 PDT 2014
Friends,
I have a class that needs two constructors:
class Foo{
this(int x){}
this(T)(T x) if(!is(T == int)){}
}
void main(){}
But this does not compile because the two constructors conflict:
buggy.d(3): Error: template buggy.Foo.__ctor(T)(T x) if (!is(T ==
int)) conflicts with constructor buggy.Foo.this at buggy.d(2)
Of course, I can just have one constructor that doesn't have the
constraint and then use a static if to redirect to a private
method, but that seems clunky to me. (not to mention it would
complicate the documentation.)
Any ideas?
Cheers,
Charles McAnany.
More information about the Digitalmars-d-learn
mailing list