Re: A look inside "filter" function defintion

2022-08-14 Thread Kyle Ingraham via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 12:39:41 UTC, pascal111 wrote: but I'm still stuck. Do you have a down-to-earth example for beginners to understand this concept? I often go back to this post when writing templates: https://dlang.org/blog/2020/07/31/the-abcs-of-templates-in-d/ It helped me when I

Re: Exercise at end of Ch. 56 of "Programming in D"

2022-08-14 Thread johntp via Digitalmars-d-learn
On Monday, 15 August 2022 at 02:59:59 UTC, Ali Çehreli wrote: On 8/14/22 19:23, Ali Çehreli wrote: class Point { int x; int y; Color color; // ... override size_t toHash() const { return x + y; I just saw this second reply. Might not be good if you have Point(1,2) and Poin

Re: Exercise at end of Ch. 56 of "Programming in D"

2022-08-14 Thread johntp via Digitalmars-d-learn
On Monday, 15 August 2022 at 02:23:34 UTC, Ali Çehreli wrote: Wow! Are people actually working on those? :) Absolutely. Thanks for the book. I'm enjoying it. At first, I couldn't even get the code to compile due to const-correctness issues with opCmp. :/ I used the following cast(): f

Re: Exercise at end of Ch. 56 of "Programming in D"

2022-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 8/14/22 19:23, Ali Çehreli wrote: > // BUG DUE TO WISHFUL THINKING: > override size_t toHash() const { >/* Since the 'points' member is an array, we can take > * advantage of the existing toHash algorithm for > * array types. */ >return typeid(points).

Re: Exercise at end of Ch. 56 of "Programming in D"

2022-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 8/14/22 18:47, johntp wrote: > I'm using DMD64 D Compiler v2.100.0 on linux mint. Same version here. > I copied the author's > solution and got the same thing. Wow! Are people actually working on those? :) At first, I couldn't even get the code to compile due to const-correctness issues wi

Exercise at end of Ch. 56 of "Programming in D"

2022-08-14 Thread johntp via Digitalmars-d-learn
I'm using DMD64 D Compiler v2.100.0 on linux mint. I kept getting an assertion error for my solution to the exercises at the end of Chapter 56 of "Programming in D", so I copied the author's solution and got the same thing. The exercise is the very last one (exercise 3) about overriding ```d

Re: Index an AliasSeq with a run-time index

2022-08-14 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 14 August 2022 at 10:41:20 UTC, ag0aep6g wrote: On 14.08.22 12:08, Per Nordlöw wrote: How do I index an `AliasSeq` with an integer known at run-time? Thanks

Re: Index an AliasSeq with a run-time index

2022-08-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.08.22 12:08, Per Nordlöw wrote: How do I index an `AliasSeq` with an integer known at run-time? With a `switch` that has a `case` for every possible index: import std.meta: AliasSeq; alias seq = AliasSeq!("foo", "bar", "baz"); string f(size_t rti) { sw: switch (rti) {

Index an AliasSeq with a run-time index

2022-08-14 Thread Per Nordlöw via Digitalmars-d-learn
How do I index an `AliasSeq` with an integer known at run-time?