digitalmars.D - opSliceAssign
- Manfred Nowak <svv1999 hotmail.com> Aug 18 2005
- Chris Sauls <ibisbasenji gmail.com> Aug 18 2005
- Stewart Gordon <smjg_1998 yahoo.com> Aug 23 2005
- Chris Sauls <ibisbasenji gmail.com> Aug 23 2005
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> Aug 18 2005
- Shammah Chancellor <Shammah_member pathlink.com> Aug 19 2005
Because assigning to array slices is possible, why dont D has an opSliceAssign? -manfred
Aug 18 2005
Manfred Nowak wrote:Because assigning to array slices is possible, why dont D has an opSliceAssign? -manfred
Its a good question, and probably has something to do with determining the signature of the function. Now that D has its "typesafe variadic arguments" I figure an opSliceAssign might look like: # class Foo { # int[] data; # # size_t opSliceAssign (in size_t begin, in size_t end, in int[] values...) { # size_t wall = values.length < end ? values.length : end; # for (size_t idx = begin; idx < wall; idx++) # data[idx] = values[idx - begin]; # return wall - begin; # } # } -- Chris Sauls
Aug 18 2005
Chris Sauls wrote: <snip>Its a good question, and probably has something to do with determining the signature of the function. Now that D has its "typesafe variadic arguments" I figure an opSliceAssign might look like: # class Foo { # int[] data; # # size_t opSliceAssign (in size_t begin, in size_t end, in int[] values...) {
Why the ...? And why return a size_t? And why not have the order match opIndexAssign? int[] opSliceAssign(int[] values, size_t begin, size_t end) { ... } Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Aug 23 2005
Stewart Gordon wrote:Chris Sauls wrote: <snip>Its a good question, and probably has something to do with determining the signature of the function. Now that D has its "typesafe variadic arguments" I figure an opSliceAssign might look like: # class Foo { # int[] data; # # size_t opSliceAssign (in size_t begin, in size_t end, in int[] values...) {
Why the ...?
pointless. A formal array would work fine.And why return a size_t?
was on to.And why not have the order match opIndexAssign?
yes it should match, just as you presented below.int[] opSliceAssign(int[] values, size_t begin, size_t end) { ... }
-- Chris Sauls
Aug 23 2005
"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:de1lv7$1uln$1 digitaldaemon.com...Because assigning to array slices is possible, why dont D has an opSliceAssign?
I've asked this same question many times myself.
Aug 18 2005
In article <de25l3$2n0u$1 digitaldaemon.com>, Jarrett Billingsley says..."Manfred Nowak" <svv1999 hotmail.com> wrote in message news:de1lv7$1uln$1 digitaldaemon.com...Because assigning to array slices is possible, why dont D has an opSliceAssign?
I've asked this same question many times myself.
I think the rationale for this is: A slice is supposed to return another instance of the object with a subrange. Because of the order of operation, you can then assign to it, and opAssign would then take over IE: foo[1..2] = 10 would be rewritten as: foo.opSlice(1,2).opAssign(10) However, this is not really a good thing. Since if that's how normal slices worked, using opslice to imply a copy on normal arrays wouldn't work. Normally when a slice operator is used with an array as an lvalue, it causes an array copy. This is functionally objects cannot obtain currently. I vote for an opSliceAssign as well! :)
Aug 19 2005









Chris Sauls <ibisbasenji gmail.com> 