digitalmars.D - Operator inconsistencies
- Benjamin Herr (14/14) Oct 23 2004 Hello, D!
- Tyro (3/19) Oct 23 2004 a = b[foo .. bar];
- Benjamin Herr (14/20) Oct 23 2004 I think there is the subtle difference that a[] = b[..] copies while a =...
- Walter (3/16) Oct 30 2004 Just overload the .. operator with opSlice and have it return an array.
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)
Oct 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)
Oct 23 2004
Tyro wrote:Benjamin Herr wrote: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; }how can I implement arraylike a[] = b[foo ... bar]?a = b[foo .. bar]; Unless I completely misunderstood your question!
Oct 23 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.
Oct 30 2004