On 6/11/2015 8:03 AM, Dicebot wrote:
On the other hand they have one important advantage: all type arguments must comply to one or more trairs and thus bodies of generics are checked before institation. You are only allowed to call methods and operations of generic arguments that are defined in relevan trait. This is huge win for code hygiene compared to D.
On the other hand, generic bodies in D can inquire if various additional traits are available, and then adapt:
struct S(R) if (isInputRange!R) { ... static if (isForwardRange!R) { R save() { auto result = this; result.r = r.save; return result; } } ... } This kind of thing is used extensively in Phobos generics.