On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote:
import std.stdio : writeln;
import std.traits : ConstOf;
auto max(T)(T x, T y)
{
writeln("General template");
return x > y ? x : y;
}
auto max(T: const U, U)(T* x, T* y) <----- Changed `ConstOf!U`
to `const U`
{
writeln("Const template");
return *x > *y ? x : y;
}
void main(){
const double p = 2.4, q = 3;
writeln(max(&p, &q)); //Prints "Const template"
}
This is great Meta, thanks very much! I was trying to avoid using
template constraints because the more cases you add, the more
complicated the constraints get.