Re: CTFE and return statement from delegate

2025-07-06 Thread Rajesh via Digitalmars-d-learn
On Thursday, 3 July 2025 at 15:29:53 UTC, Nick Treleaven wrote: On Monday, 30 June 2025 at 04:51:58 UTC, Rajesh wrote: On Sunday, 29 June 2025 at 21:56:19 UTC, 0xEAB wrote: On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: Is there a restriction that I cannot call **return** from foreach

Re: CTFE and return statement from delegate

2025-07-03 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 30 June 2025 at 14:30:49 UTC, Manfred Nowak wrote: On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: [...] ```d struct Problem { this(int val) { foreach (int number; myType) return; ``` [...] Is there a restriction [...] Yes. 'this' is not allowed

Re: CTFE and return statement from delegate

2025-07-03 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 30 June 2025 at 04:51:58 UTC, Rajesh wrote: On Sunday, 29 June 2025 at 21:56:19 UTC, 0xEAB wrote: On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: Is there a restriction that I cannot call **return** from foreach (opApply delegate) if it is executed at compile time? To me thi

Re: CTFE and return statement from delegate

2025-07-01 Thread Rajesh via Digitalmars-d-learn
On Monday, 30 June 2025 at 14:30:49 UTC, Manfred Nowak wrote: On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: [...] ```d struct Problem { this(int val) { foreach (int number; myType) return; ``` [...] Is there a restriction [...] Yes. 'this' is not allowed

Re: CTFE and return statement from delegate

2025-07-01 Thread Rajesh via Digitalmars-d-learn
On Monday, 30 June 2025 at 14:22:47 UTC, H. S. Teoh wrote: On Mon, Jun 30, 2025 at 04:51:27AM +, Rajesh via Digitalmars-d-learn wrote: [...] ``` Error: variable `__capture` cannot be read at compile time onlineapp.d(27):called from here: `Problem(0).this(1)` auto compile_time_var = P

Re: CTFE and return statement from delegate

2025-06-30 Thread WraithGlade via Digitalmars-d-learn
On Monday, 30 June 2025 at 14:22:47 UTC, H. S. Teoh wrote: ... This article may help clear up any misunderstanding that may have caused this problem: https://wiki.dlang.org/Compile-time_vs._compile-time T That is a wonderful article! I just finished reading it. Thank you for link

Re: CTFE and return statement from delegate

2025-06-30 Thread Manfred Nowak via Digitalmars-d-learn
On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: [...] ```d struct Problem { this(int val) { foreach (int number; myType) return; ``` [...] Is there a restriction [...] Yes. 'this' is not allowed to have a 'return' (15.13.0.2) ... and to exit a 'foreach'-loop

Re: CTFE and return statement from delegate

2025-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 30, 2025 at 04:51:27AM +, Rajesh via Digitalmars-d-learn wrote: [...] > ``` > Error: variable `__capture` cannot be read at compile time > onlineapp.d(27):called from here: `Problem(0).this(1)` > auto compile_time_var = Problem(1); > ``` [...] This article may help clear up

Re: CTFE and return statement from delegate

2025-06-29 Thread Rajesh via Digitalmars-d-learn
On Sunday, 29 June 2025 at 21:56:19 UTC, 0xEAB wrote: On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: Is there a restriction that I cannot call **return** from foreach (opApply delegate) if it is executed at compile time? To me this looks like a compiler bug where it runs into a wrong

Re: CTFE and return statement from delegate

2025-06-29 Thread Rajesh via Digitalmars-d-learn
On Monday, 30 June 2025 at 02:21:29 UTC, WraithGlade wrote: On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: This is simplified code which I am using in my project. ... Welcome to the forum and good luck in your programming endeavors Rajesh. Honestly, it isn't clear what you are even

Re: CTFE and return statement from delegate

2025-06-29 Thread WraithGlade via Digitalmars-d-learn
On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: This is simplified code which I am using in my project. ... Welcome to the forum and good luck in your programming endeavors Rajesh. Honestly, it isn't clear what you are even trying to do in your code and thus it would probably be eas

Re: CTFE and return statement from delegate

2025-06-29 Thread 0xEAB via Digitalmars-d-learn
On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote: Is there a restriction that I cannot call **return** from foreach (opApply delegate) if it is executed at compile time? To me this looks like a compiler bug where it runs into a wrong assumption once it finds the return statement in the fo

CTFE and return statement from delegate

2025-06-29 Thread Rajesh via Digitalmars-d-learn
This is simplified code which I am using in my project. ``` struct NumberType { int num; int opApply(int delegate(int) dg) { int result = dg(num); return result; } } struct Problem { int value; this(int val) { auto myType = NumberType(18);