Multiple Template Specialization Types (in D1)?
Nick Sabalausky
a at a.a
Tue Jul 1 16:49:43 PDT 2008
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
news:g4e7em$2146$1 at digitalmars.com...
> "Nick Sabalausky" <a at a.a> wrote in message
> news:g4e7bg$20n8$1 at digitalmars.com...
>> Is there a way to do something like this in D1 without resorting to
>> function overloading?:
>>
>> void Foo(T : char, wchar, dchar)(T arg) {/*code*/}
>
> It's not perfect, but:
>
> void Foo(T)(T arg)
> {
> static assert(is(T == char) || is(T == wchar) || is(T == dchar), "T
> must be char, wchar, or dchar");
> }
>
> D2 would let you put that in a template condition, but D1's stuck with a
> static assert.
>
Yea, I had actually tried that. It technically works, but when the assert
fails the compiler just gives you the file/line of the static assert itself,
and doesn't give any indication of what file/line attempted the failed
instantiation of Foo (which would be a nightmare to track down, particularly
if Foo was in a library).
More information about the Digitalmars-d-learn
mailing list