Re: Range length property

2018-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/10/18 6:07 PM, Cym13 wrote: On Tuesday, 10 April 2018 at 20:08:14 UTC, Jonathan M Davis wrote: On Tuesday, April 10, 2018 19:47:10 Nordlöw via Digitalmars-d-learn wrote: On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: > On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wro

Re: Range length property

2018-04-10 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 10, 2018 at 10:07:40PM +, Cym13 via Digitalmars-d-learn wrote: [...] > On the other hand I don't think the end user should have to scratch > his head to find the length of a range, especially if it's not trivial > to get (say, O(log n) kind of case). Therefore exposing a method in >

Re: Range length property

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 10, 2018 22:07:40 Cym13 via Digitalmars-d-learn wrote: > On Tuesday, 10 April 2018 at 20:08:14 UTC, Jonathan M Davis wrote: > > On Tuesday, April 10, 2018 19:47:10 Nordlöw via > > > > Digitalmars-d-learn wrote: > >> On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: >

Re: Range length property

2018-04-10 Thread Cym13 via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 20:08:14 UTC, Jonathan M Davis wrote: On Tuesday, April 10, 2018 19:47:10 Nordlöw via Digitalmars-d-learn wrote: On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: > On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: >> Should ranges always provid

Re: Range length property

2018-04-10 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 20:16:18 UTC, Steven Schveighoffer wrote: e.g. std.array.array is going to pre-allocate an array of the correct length and fill it in, vs. appending each element as it gets them from the range. Personally, I would store the length because typically a container ran

Re: Range length property

2018-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/10/18 4:08 PM, Jonathan M Davis wrote: On Tuesday, April 10, 2018 19:47:10 Nordlöw via Digitalmars-d-learn wrote: I'm thinking of my own container Hashmap having its range ByKeyValue requiring one extra word of memory to store the iteration count which, in turn, can be used to calculate the

Re: Range length property

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 10, 2018 19:47:10 Nordlöw via Digitalmars-d-learn wrote: > On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: > > On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: > >> Should ranges always provide a length property? > > > > No. > > > >> If so, in which cases

Re: Range length property

2018-04-10 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 14:34:40 UTC, Adam D. Ruppe wrote: On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: Should ranges always provide a length property? No. If so, in which cases is a length property an advantage or a requirement? Just provide it whenever it is cheap to do

Re: Range length property

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 10, 2018 14:25:52 Nordlöw via Digitalmars-d-learn wrote: > Should ranges always provide a length property? > > If so, in which cases is a length property an advantage or a > requirement? Whether a range has a length property or not is primarily dependent on how efficient it is to

Re: Range length property

2018-04-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 14:25:52 UTC, Nordlöw wrote: Should ranges always provide a length property? No. If so, in which cases is a length property an advantage or a requirement? Just provide it whenever it is cheap to do so. If you need to do complex calculations or especially loop o

Range length property

2018-04-10 Thread Nordlöw via Digitalmars-d-learn
Should ranges always provide a length property? If so, in which cases is a length property an advantage or a requirement?