Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Saturday, 21 August 2021 at 13:45:59 UTC, Ali Çehreli wrote: On 8/21/21 1:31 AM, Tejas wrote: > I was more impressed that you found that hack in the first place I can't take credit. :) 'static foreach' had that difference since its inception. The spec says "If a new scope is desired for

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/21/21 1:31 AM, Tejas wrote: > I was more impressed that you found that hack in the first place I can't take credit. :) 'static foreach' had that difference since its inception. The spec says "If a new scope is desired for each expansion, use another set of braces:"

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Saturday, 21 August 2021 at 06:58:47 UTC, Ali Çehreli wrote: On 8/20/21 11:19 PM, Tejas wrote: [...] Yes. 'static foreach' does not introduce scope, which can be pretty useful. For example, one can define functions at module scope. The subtle differences between 'static foreach' and

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/20/21 11:19 PM, Tejas wrote: On Saturday, 21 August 2021 at 06:03:33 UTC, Ali Çehreli wrote: On 8/20/21 10:37 PM, Alexandru Ermicioi wrote: [...] Cool! Much better. :) I could not do [...] Did you use that double curly bracket in `static foreach` so that you don't get error for

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Tejas via Digitalmars-d-learn
On Saturday, 21 August 2021 at 06:03:33 UTC, Ali Çehreli wrote: On 8/20/21 10:37 PM, Alexandru Ermicioi wrote: [...] Cool! Much better. :) I could not do [...] Did you use that double curly bracket in `static foreach` so that you don't get error for declaring stuff inside `static

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/20/21 10:37 PM, Alexandru Ermicioi wrote: On Saturday, 21 August 2021 at 05:34:59 UTC, Alexandru Ermicioi wrote: ... Also there is no need for mixing string code here. You can get the field using __traits(getMember, this, member). Cool! Much better. :) I could not do static

Re: Lexicographical object comparison by selected members of a struct

2021-08-20 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Saturday, 21 August 2021 at 04:34:46 UTC, Ali Çehreli wrote: ... Consider __traits(identifier, member) instead. This one should return member name as string, removing the need of memberName function. Also you could have an annotation @Equality.Include for example, and make mixin scan

Re: Lexicographical object comparison by selected members of a struct

2021-08-20 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Saturday, 21 August 2021 at 05:34:59 UTC, Alexandru Ermicioi wrote: ... Also there is no need for mixing string code here. You can get the field using __traits(getMember, this, member).

Lexicographical object comparison by selected members of a struct

2021-08-20 Thread Ali Çehreli via Digitalmars-d-learn
Sometimes I need comparison operators that should consider only some members of a struct: struct S { int year; // Primary member int month;// Secondary member string[] values; // Irrelevant } I've been using the laziest tuple+tupleof solution in some of my structs: