Thread overview
Operator inconsistencies
Oct 23, 2004
Benjamin Herr
Oct 23, 2004
Tyro
Oct 24, 2004
Benjamin Herr
Oct 30, 2004
Walter
October 23, 2004
Hello, D!

I was taught that overloaded operators should emulate their function on primitive data types.
With ints (and probably structs), a += b and a = a + b is essentially the same.
With objects, a += b is a.opAddAssign(b) or the reverse and a = a + b is a = a.opAdd(b), which is clearly different as the former cannot emulate the latter's reference assignment.
This leads me to the assumption that we lack a operator for valueish assignment that is different from the reference assignment one.
What am I missing?

On a completely unrelated note, how can I implement arraylike a[] = b[foo ... bar]?

  -ben (the newbie one)
October 23, 2004
Benjamin Herr wrote:
> Hello, D!
> 
> I was taught that overloaded operators should emulate their function on primitive data types.
> With ints (and probably structs), a += b and a = a + b is essentially the same.
> With objects, a += b is a.opAddAssign(b) or the reverse and a = a + b is a = a.opAdd(b), which is clearly different as the former cannot emulate the latter's reference assignment.
> This leads me to the assumption that we lack a operator for valueish assignment that is different from the reference assignment one.
> What am I missing?
> 
> On a completely unrelated note, how can I implement arraylike a[] = b[foo ... bar]?

a = b[foo .. bar];

Unless I completely misunderstood your question!

>   -ben (the newbie one)
October 24, 2004
Tyro wrote:
> Benjamin Herr wrote:
>> how can I implement arraylike a[] = b[foo ... bar]?
> 
> a = b[foo .. bar];
> 
> Unless I completely misunderstood your question!

I think there is the subtle difference that a[] = b[..] copies while a = b makes a refer the same data as b.

int main() {
        char[] a = "Hello, World".dup;
        char[] b, c;
        b = a[0 .. length];
        c.length = a.length;
        c[] = a[0 .. length];

        a[7 .. 12] = "Tyro!";

        printf("b is: %.*s\n", b);
        printf("c is: %.*s\n", c);
        return 0;
}
October 30, 2004
"Benjamin Herr" <ben@0x539.de> wrote in message news:clelpa$oae$1@digitaldaemon.com...
> Hello, D!
>
> I was taught that overloaded operators should emulate their function on
> primitive data types.
> With ints (and probably structs), a += b and a = a + b is essentially
> the same.
> With objects, a += b is a.opAddAssign(b) or the reverse and a = a + b is
> a = a.opAdd(b), which is clearly different as the former cannot emulate
> the latter's reference assignment.
> This leads me to the assumption that we lack a operator for valueish
> assignment that is different from the reference assignment one.
> What am I missing?
>
> On a completely unrelated note, how can I implement arraylike a[] = b[foo ... bar]?

Just overload the .. operator with opSlice and have it return an array.