On Thursday, 8 September 2016 at 23:34:13 UTC, Walter Bright
wrote:
On 9/8/2016 5:10 AM, Andrei Alexandrescu wrote:
Consider the pattern of overloads:
template foo(T) if (condition!T) { }
template foo(T) if (!condition!T) { }
It makes condition!T a user-facing constraint, which it
should not be.
This looks like a nice guideline. Good work. Pushing the roof
now. -- Andrei
An example of doing it better, the put() template:
https://github.com/dlang/phobos/blob/master/std/range/primitives.d#L295
Something we need to move away from, the 17 overloads of
formatValue() in:
https://github.com/dlang/phobos/blob/master/std/format.d#L1319
all that differ only in the constraint.
Yay! Finally!
This is exactly what I said in another recent thread:
overloads should be avoided, especially if something is meant to
be for all types - do it with static if inside one function,
which in turn will have MUCH MUCH easier constraints (or none at
all).
I think overload is a most of the time useless C++ relict.