Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-25 Thread Imperatorn via Digitalmars-d-learn
On Monday, 24 October 2022 at 21:52:18 UTC, Ali Çehreli wrote: On 10/24/22 14:26, Per Nordlöw wrote: [...] Another option is to use range functions where front() returns a Tuple. We have an esoteric feature where a tuple expands automatically in foreach loops: import std.typecons : tuple;

Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/22 14:26, Per Nordlöw wrote: What property of a container (type) `T` enables iteration as ```d foreach (k, v; T.init) {     ... } ``` ? I thought it sufficed to define `T.byKeyValue` but its presence seem to have no effect. Another option is to use range functions where front() ret

Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 24, 2022 at 09:26:14PM +, Per Nordlöw via Digitalmars-d-learn wrote: > What property of a container (type) `T` enables iteration as > > ```d > foreach (k, v; T.init) > { > ... > } > ``` > > ? I thought it sufficed to define `T.byKeyValue` but its presence seem > to have no ef

Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread Per Nordlöw via Digitalmars-d-learn
What property of a container (type) `T` enables iteration as ```d foreach (k, v; T.init) { ... } ``` ? I thought it sufficed to define `T.byKeyValue` but its presence seem to have no effect.

Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread rikki cattermole via Digitalmars-d-learn
From there down: https://dlang.org/spec/statement.html#foreach_over_struct_and_classes