Why doesn't this work in D2?

bearophile bearophileHUGS at lycos.com
Sun Jun 27 10:47:15 PDT 2010


Simen kjaeraas:
> void foo(T,U)(const T[] a, U b) if (is(Unqual!T == Unqual!U)) {
> ...
> }

Yes, this was my solution.
My first solution was:

import std.traits: Unqual;
void foo(T)(T[] a, Unqual!T b) {}
void main () {
    "asd".foo('s');
}

But it doesn't work, and I don't know if it's supposed to work.

A problem with Unqual is that it strips away too much, so something like this can be better:

void foo(TA, T)(const TA[] a, T b) if (is(Deconst!TA == Deconst!T)) {}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list