Re: Can opDollar support a jagged 2D array?

2020-10-02 Thread Steven Schveighoffer via Digitalmars-d-learn
pass enough context to the opDollar? The nice thing about opDollar is it's a simple mechanism. But as a simple mechanism, it's hard to say how to give it enough context in this case. In this specific case, you would need to know the index of the first parameter. But what if the

Re: Can opDollar support a jagged 2D array?

2020-10-02 Thread James Blachly via Digitalmars-d-learn
On 10/2/20 9:32 AM, Steven Schveighoffer wrote: This seems like an oversight. But it's not impossible. Thank you Steve. Is there any chance that this mechanism will ever be revised? Presumably it would require a DIP. Just curry the information to the receiver. opDollar doesn'

Re: Can opDollar support a jagged 2D array?

2020-10-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/20 10:34 PM, James Blachly wrote: Suppose I have a data structure encoding sequence lengths: seq1: 0 1 2 ... N seq2: 0 1 2 3 4 ... M seq3: 0 1 ... P I would like to write opIndex and opDollar to support the notation obj[seq, x .. $] to retrieve sequences. However, given that

Can opDollar support a jagged 2D array?

2020-10-01 Thread James Blachly via Digitalmars-d-learn
Suppose I have a data structure encoding sequence lengths: seq1: 0 1 2 ... N seq2: 0 1 2 3 4 ... M seq3: 0 1 ... P I would like to write opIndex and opDollar to support the notation obj[seq, x .. $] to retrieve sequences. However, given that opDollar is templated on dimension (always 1 in

Re: opDollar any

2017-09-29 Thread Ali Çehreli via Digitalmars-d-learn
On 09/29/2017 11:34 AM, Joseph wrote: Trying to do multi-dimension array but op-dollar doesn't seem to support arbitrary dimensions @property int opDollar(size_t dim : k)() { return dims[k]; } It's called by multi-dimensional opIndex (or opSlice and perhaps others?; c

opDollar any

2017-09-29 Thread Joseph via Digitalmars-d-learn
Trying to do multi-dimension array but op-dollar doesn't seem to support arbitrary dimensions @property int opDollar(size_t dim : k)() { return dims[k]; }

Re: opDollar and length

2014-12-28 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 28/12/14 19:21, Tobias Pankrath via Digitalmars-d-learn wrote: To allow slicing for types that don't have a length property but are terminated by a sentinel value, like null terminated strings or single linked lists. It's usefull for multi-dimensional containers as well. Ah, clear. Thanks

Re: opDollar and length

2014-12-28 Thread ketmar via Digitalmars-d-learn
On Sun, 28 Dec 2014 19:02:59 +0100 Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > A question that suddenly occurred to me, and I realized I didn't know the > answer. > > Why is it necessary/desirable to define separate .length and .opDollar > methods > for

Re: opDollar and length

2014-12-28 Thread Jonathan M Davis via Digitalmars-d-learn
swer. > > > > Why is it necessary/desirable to define separate .length and > > .opDollar methods for custom types? > > To allow slicing for types that don't have a length property but > are terminated by a sentinel value, like null terminated strings > or s

Re: opDollar and length

2014-12-28 Thread Tobias Pankrath via Digitalmars-d-learn
On Sunday, 28 December 2014 at 18:12:42 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: A question that suddenly occurred to me, and I realized I didn't know the answer. Why is it necessary/desirable to define separate .length and .opDollar methods for custom types? To

opDollar and length

2014-12-28 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
A question that suddenly occurred to me, and I realized I didn't know the answer. Why is it necessary/desirable to define separate .length and .opDollar methods for custom types?

Re: opDollar fixed??

2012-12-29 Thread Jonathan M Davis
On Saturday, December 29, 2012 23:15:34 Era Scarecrow wrote: > Oh yes, dmd version 2.60, Windows 32bit version. I pretty sure > it would propagate all versions. That would be your problem. It's not fixed in 2.060. It was fixed since then. Use the latest from git or the current beta. - Jonathan

Re: opDollar fixed??

2012-12-29 Thread Era Scarecrow
Oh yes, dmd version 2.60, Windows 32bit version. I pretty sure it would propagate all versions.

opDollar fixed??

2012-12-29 Thread Era Scarecrow
Wasn't opDollar was fixed? Slices don't seem to be working... In one of my tests (can't duplicate here for some reason) using __dollar when it would see __dollar it complained about needing 'this' access. struct S { int[] x; this(int[] x) {this.x = x;} int op

Re: opDollar()

2011-05-02 Thread Don
so, what is the signature for opDollar() in a struct. I'm getting errors trying to implement this. That parameter means number of dimension. When implementing some kind of multidimensional array (e.g. an 2D raster Image) you'd have: img[$-1, $-1] = lastValue; // the first dollar should resolv

Re: opDollar()

2011-03-26 Thread Jonathan M Davis
> Also, what is the signature for opDollar() in a struct. I'm getting > errors trying to implement this. I don't think that opDollar is actually implemented yet. See http://d.puremagic.com/issues/show_bug.cgi?id=3474 - Jonathan M Davis

Re: opDollar()

2011-03-26 Thread Dmitry Olshansky
On 26.03.2011 11:03, Caligo wrote: "In the expression a[, ...,], if $ occurs in, it is rewritten as a.opDollar!(i)()." -- TDPL, pg 380 Is that correct? if so, could some one give an example code? I don't understand the need for the parameter. Also, what is the signature for

opDollar()

2011-03-26 Thread Caligo
"In the expression a[, ..., ], if $ occurs in , it is rewritten as a.opDollar!(i)()." -- TDPL, pg 380 Is that correct? if so, could some one give an example code? I don't understand the need for the parameter. Also, what is the signature for opDollar() in a struct. I'm g

Re: cannot make opDollar work

2010-12-12 Thread Andrej Mitrovic
I think this might have been reported: http://d.puremagic.com/issues/show_bug.cgi?id=3474 On 12/12/10, spir wrote: > Hello, > > Test case: > > struct S { > int[] ints; > int opDollar () {return this.ints.length;} > int opIndex (int i) {return this.ints[i];}

cannot make opDollar work

2010-12-12 Thread spir
Hello, Test case: struct S { int[] ints; int opDollar () {return this.ints.length;} int opIndex (int i) {return this.ints[i];} int[] opSlice (int i, int j) {return this.ints[i..j];} } unittest { S s = S([3,2,1]); // _link_ error on each line: // Error: undefined