View mode: basic / threaded / horizontal-split · Log in · Help
August 18, 2005
opSliceAssign
Because assigning to array slices is possible, why dont D has an 
opSliceAssign?

-manfred
August 18, 2005
Re: opSliceAssign
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
August 18, 2005
Re: opSliceAssign
"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.
August 19, 2005
Re: opSliceAssign
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! :)
August 23, 2005
Re: opSliceAssign
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.
August 23, 2005
Re: opSliceAssign
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 ...?
I thought it was clever at the time... Now that I think about it, I guess it is kind of 
pointless.  A formal array would work fine.

> And why return a size_t?
I think I was envisioning it returning a length or something... honestly I forget what I 
was on to.

> And why not have the order match 
> opIndexAssign?
That was just because of the variadic at the end.  Once that's gone, there's no reason, so 
yes it should match, just as you presented below.

> 
>     int[] opSliceAssign(int[] values, size_t begin, size_t end) { ... }
> 

-- Chris Sauls
Top | Discussion index | About this forum | D home