On Monday, 5 October 2015 at 08:14:14 UTC, Manu wrote:
This comes up in many cases, I presume I've just missed something really obvious...?

The obvious thing is to change it so that the template declaration in Phobos actually has a template constraint on it. But in general, these sorts of templates were not designed with the idea that they would be overloaded in user code. And to be honest, in this case, it could be a big problem if they were. These traits are used in code under the assumption that they only allow built-in types, and if you could overload them, then suddenly, that types would get past the template constraints on templates which were not designed to handle anything but built-in types. And at least some of the documentation is clear that they are intended for built-in types only. e.g. this is the ddoc comment on isUnsigned:

    Detect whether $(D T) is a built-in unsigned numeric type.

So, you could certainly declare your own isUnsigned and similar traits, but they're not going to overload with the ones in std.traits and thus would likely have to fully qualified. I suspect that that thwarts what you're trying to do, but I think that it's pretty clear that these traits were _not_ intended to be true for any user-defined type.

In general, the traits in std.traits are designed to match an exact set of built-in types and that's it. And code using them is going to rely on that, making overloading them very risky IMHO.

- Jonathan M Davis

Reply via email to