Daily downloads in decline
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 11 13:18:54 PDT 2015
On Thursday, 11 June 2015 at 19:31:52 UTC, Walter Bright wrote:
> 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.
It's not *quite* the same. I believe Rust traits are closer to
C++ concepts.
More information about the Digitalmars-d
mailing list