Re: Type constraint

2023-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 3, 2023 7:46:42 PM MDT Joel via Digitalmars-d-learn wrote: > I think the if without static is still static, since it's part of > the function name part, or so (outside of the curly bracket > scope). if on a template (or on a templated function) is a template constraint, in

Re: Type constraint

2023-10-03 Thread Joel via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 17:42:51 UTC, Jonathan M Davis wrote: On Tuesday, October 3, 2023 8:35:31 AM MDT Joel via Digitalmars-d-learn wrote: [...] Yeah. static if will compile in the code in that branch based on whether the condition is true, whereas if without the static will branch

macOS Sonoma Linker Issue

2023-10-03 Thread confuzzled via Digitalmars-d-learn
Any known workaround for this most recent issue on macOS Sonoma? The file I'm compiling contains a blank main() without any imports but this error shows up on everything I've attempted to compile since upgrading to Sonoma. (dmd-2.105.2) confuzzled@test ~ % dmd add ld: multiple errors: symbol

Re: Key and value with ranges

2023-10-03 Thread christian.koestlin via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 20:22:30 UTC, Andrey Zherikov wrote: On Tuesday, 3 October 2023 at 19:57:06 UTC, christian.koestlin wrote: On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov wrote: On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: [...] Slightly

Re: Key and value with ranges

2023-10-03 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 19:57:06 UTC, christian.koestlin wrote: On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov wrote: On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: [...] Slightly improved: ```d import std; [...] Thanks .. the thing with ref result

Re: Key and value with ranges

2023-10-03 Thread christian.koestlin via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov wrote: On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: [...] Slightly improved: ```d import std; [...] Thanks .. the thing with ref result is very clever! Should `ref result` be `return result`? Kind regards,

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 18:29:49 UTC, Salih Dincer wrote: More importantly, is there a priority order? Because in our last example, when we leave a single overload, all features are executed through the ref opIndex except the bit: The spec says: If an index expression can be rewritten

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 18:09:55 UTC, Imperatorn wrote: At the very least, the spec should do a better job of documenting when the compiler will try a fallback and when it won't. Who will be the hero and add the documentation?  More importantly, is there a priority order? Because

Re: T[] opIndex() Error: .. signal 11

2023-10-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 17:05:46 UTC, Steven Schveighoffer wrote: ```d void main() { S s = 0; { scope int[] __r3 = s.opIndex()[]; ulong __key4 = 0LU; for (; __key4 < __r3.length; __key4 += 1LU) {

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 17:52:20 UTC, Paul Backus wrote: On Tuesday, 3 October 2023 at 16:45:39 UTC, Steven Schveighoffer wrote: OK, so it's not as bad as I thought, but surely the compiler should recognize that `opIndexAssign(val, idx)` doesn't work, but `opIndex(idx) = val` does?

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 16:45:39 UTC, Steven Schveighoffer wrote: OK, so it's not as bad as I thought, but surely the compiler should recognize that `opIndexAssign(val, idx)` doesn't work, but `opIndex(idx) = val` does? Maybe. On the other hand, if you make a typo in the body of your

Re: Type constraint

2023-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 3, 2023 8:35:31 AM MDT Joel via Digitalmars-d-learn wrote: > Oh, I found, > ```d > static if (isIntegral!T) > ``` > seems to work. Yeah. static if will compile in the code in that branch based on whether the condition is true, whereas if without the static will branch at

Re: T[] opIndex() Error: .. signal 11

2023-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/3/23 11:12 AM, Joel wrote: The following program crashes, but doesn’t if I change (see title) T[] to auto. The program doesn’t even use that method/function. What’s the story? It's a stack overflow. when doing foreach on your type, the compiler *always* uses a slice first if it

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/3/23 12:09 PM, Paul Backus wrote: On Tuesday, 3 October 2023 at 13:07:00 UTC, Steven Schveighoffer wrote: Now, you can define a further `opIndexAssign(T val, size_t idx)`. However, now you lose capabilities like `a[0]++`, which I don't think has a possibility of implementing using an

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 13:07:00 UTC, Steven Schveighoffer wrote: Now, you can define a further `opIndexAssign(T val, size_t idx)`. However, now you lose capabilities like `a[0]++`, which I don't think has a possibility of implementing using an `opIndex` operator, and it would be

Re: T[] opIndex() Error: .. signal 11

2023-10-03 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 15:12:34 UTC, Joel wrote: The following program crashes, but doesn’t if I change (see title) T[] to auto. The program doesn’t even use that method/function. What’s the story? ```d // Adding program - literal functions import std; struct List(T) { class Node

T[] opIndex() Error: .. signal 11

2023-10-03 Thread Joel via Digitalmars-d-learn
The following program crashes, but doesn’t if I change (see title) T[] to auto. The program doesn’t even use that method/function. What’s the story? ```d // Adding program - literal functions import std; struct List(T) { class Node { T data; Node next; this(T

Re: Type constraint

2023-10-03 Thread Joel via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 14:06:37 UTC, ryuukk_ wrote: On Tuesday, 3 October 2023 at 11:43:46 UTC, Joel wrote: I’ve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) … but it isn’t working. static if (is(T==int)) works for

Re: Type constraint

2023-10-03 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 11:43:46 UTC, Joel wrote: I’ve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) … but it isn’t working. static if (is(T==int)) works for one integer type. ```d struct List(T) { auto addUp()

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 2 October 2023 at 20:42:14 UTC, Paul Backus wrote: On Monday, 2 October 2023 at 20:34:11 UTC, Salih Dincer wrote: In an old version (for example, v2.0.83), the code you implemented in the places where Slice is written above works as desired. In the most current versions, the

Type constraint

2023-10-03 Thread Joel via Digitalmars-d-learn
I’ve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) … but it isn’t working. static if (is(T==int)) works for one integer type. ```d struct List(T) { auto addUp() If (isInteger!T) { (Add numbers)