Re: Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 19 April 2024 at 22:24:17 UTC, Liam McGillivray wrote: ``` template enumMixin(alias Enum) { static foreach(m; __traits(allMembers, Enum)) static if (!__traits(isDeprecated, __traits(getMember, Enum, m))) { mixin("alias "~m~" = __traits(get

Re: Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
Well, someone on the Discord server has been helping me attempt this, but while I managed to get a solution that compiles without errors, I still get the deprecation warning. Here is what I ended up with: ``` template enumMixin(alias Enum) { static foreach(m; __traits(allMembers, Enum

Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
template: ``` template enumMixin(Enum) { private import std.traits; static foreach(member; EnumMembers!Enum) static if (__traits(isDeprecated, member)) { private alias m = __traits(identifier, member); alias m = member; } }; ``` It hasn't worked so far.

Re: Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Jack Stouffer via Digitalmars-d-learn
On Thursday, 20 January 2022 at 01:14:51 UTC, Adam Ruppe wrote: On Thursday, 20 January 2022 at 00:55:33 UTC, Jack Stouffer wrote: static foreach(member; __traits(allMembers, Manager)) member here is a string, not the member. I prefer to call it memberName. Then you __traits

Re: Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Adam Ruppe via Digitalmars-d-learn
On Thursday, 20 January 2022 at 00:55:33 UTC, Jack Stouffer wrote: static foreach(member; __traits(allMembers, Manager)) member here is a string, not the member. I prefer to call it memberName. Then you __traits(getMember, Manager, memberName) to actually get the alias you can

Re: Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Jack Stouffer via Digitalmars-d-learn
his prints nothing: ```d import std.traits; import std.stdio; enum Runnable; struct SubSystem { void run() { writeln("SubSystem ran"); } } struct Manager { @Runnable SubSystem subsystem; void run() { static fore

Re: Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 21:44:57 UTC, Jack Stouffer wrote: The error is actually coming from trying to use the result of getSymbolsByUDA in the right part of the `static foreach` huh.. I never use most of std.traits, they just complicate things. Bleh idk, I wouldn't bother

Re: Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Jack Stouffer via Digitalmars-d-learn
`static foreach`, not the call to the `run` function. Which was odd to me because I thought it just returned a `AliasSeq`. Here's a link to the erroring code with your traits change: https://run.dlang.io/is/gO84ox

Re: Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 20:46:17 UTC, Jack Stouffer wrote: static foreach(system; getSymbolsByUDA!(Manager, Runnable)) { system.run(); onlineapp.d(16): Error: value of `this` is not known at compile time The getSymbols returns aliases, meaning you hit

Using getSymbolsByUDA in a static foreach loop

2022-01-19 Thread Jack Stouffer via Digitalmars-d-learn
d the documentation of getSymbolsByUDA is unhelpful, as there are no practical use-case examples. Here's a very simplified version of my code ```d import std.traits; enum Runnable; struct SubSystem { void run(); } struct Manager { @Runnable SubSystem subsystem; void run() {

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-26 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 16:30:06 UTC, data pulverizer wrote: On Wednesday, 22 December 2021 at 16:10:42 UTC, Adam D Ruppe wrote: So OUTSIDE a function, static foreach() {{ }} is illegal because a plain {} is illegal outside a function. But INSIDE a function, static foreach

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 16:10:42 UTC, Adam D Ruppe wrote: So OUTSIDE a function, static foreach() {{ }} is illegal because a plain {} is illegal outside a function. But INSIDE a function, static foreach() {{ }} is legal, but it isn't magic about static foreach - it is just a

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 16:01:49 UTC, rikki cattermole wrote: Seems to be working just fine as of 2.098. ```d import std; void main() { static foreach(Foo; ["Abc", "def"]) {{ string str = Foo; writeln("Hello D ", str, __VERSION__);

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread ag0aep6g via Digitalmars-d-learn
On 22.12.21 17:01, rikki cattermole wrote: Anyway, AliasAssign has nothing to do with this. This "trick" creates a closure aka ``() { ... }``. Thats all its doing. From the AST dump: ``` import object; import std; void main() { {     string str = "Abc";     writeln("Hello D ",

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 15:57:29 UTC, data pulverizer wrote: I noticed that the double bracket `{{` for scoping `static foreach` is no longer part of D and it looks like it has been replaced with https://dlang.org/changelog/2.098.0.html#AliasAssign None of these things have

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread rikki cattermole via Digitalmars-d-learn
Seems to be working just fine as of 2.098. ```d import std; void main() { static foreach(Foo; ["Abc", "def"]) {{ string str = Foo; writeln("Hello D ", str, __VERSION__); }} } ``` ``` Hello D Abc2098 Hello D def2098 ``` Anyway, AliasAssi

Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread data pulverizer via Digitalmars-d-learn
Hi All, I noticed that the double bracket `{{` for scoping `static foreach` is no longer part of D and it looks like it has been replaced with https://dlang.org/changelog/2.098.0.html#AliasAssign. Could someone confirm this with a link to the DIP and any other tools that we should be using

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-17 Thread Dennis via Digitalmars-d-learn
iated templates and unrolled static foreach loops.

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 16 September 2021 at 04:54:21 UTC, james.p.leblanc wrote: Thank you for your kind response. Wow, at first the large output file from a small test program was a bit surprising .., but actually it is manageable to dig through to find the interesting bits. So, this is quite useful!

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread james.p.leblanc via Digitalmars-d-learn
On Thursday, 16 September 2021 at 03:26:46 UTC, Tejas wrote: On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc wrote: s Use the `mixin` compiler flag `dmd -mixin= file.d` Beware, this will also include **all** the mixin code from standard library and runtime. But it's manag

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread Tejas via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc wrote: Dear All, In attempting to learn and use code generation, it would be useful to be able to view the source code that gets generated. However, with various combinations of templates, UDAs, and mixins it has not been easy. I

How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread james.p.leblanc via Digitalmars-d-learn
Dear All, In attempting to learn and use code generation, it would be useful to be able to view the source code that gets generated. However, with various combinations of templates, UDAs, and mixins it has not been easy. Is there some standard way this is done? Optimal would be to print out th

Re: issue with static foreach

2021-07-22 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 July 2021 at 18:16:54 UTC, Tejas wrote: On Thursday, 22 July 2021 at 18:06:07 UTC, Paul Backus wrote: On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote: Why does this work? ```d import std; void main() { mixin("int") a; writeln(a); } ``` You can mix in a type: h

Re: issue with static foreach

2021-07-22 Thread Tejas via Digitalmars-d-learn
On Thursday, 22 July 2021 at 18:06:07 UTC, Paul Backus wrote: On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote: Why does this work? ```d import std; void main() { mixin("int") a; writeln(a); } ``` You can mix in a type: https://dlang.org/spec/type.html#mixin_types Looks like

Re: issue with static foreach

2021-07-22 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote: Why does this work? ```d import std; void main() { mixin("int") a; writeln(a); } ``` You can mix in a type: https://dlang.org/spec/type.html#mixin_types

Re: issue with static foreach

2021-07-22 Thread Tejas via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code: ```d

Re: issue with static foreach

2021-07-22 Thread someone via Digitalmars-d-learn
On Thursday, 22 July 2021 at 08:16:43 UTC, Patrick Schluter wrote: What an unreadable mess. Sorry. Indeed LoL !!! I would have done something like that: ```d mixin(format! `case r"%1$s"d : classTickerCustom%1$s lobjTicker%1$s = new classTickerCustom%1$s (lstrSymbolID);

Re: issue with static foreach

2021-07-22 Thread someone via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: Each individual string has to compile on its own. You'll have to concatenate strings and then mixin them. I forgot about that !

Re: issue with static foreach

2021-07-22 Thread Basile B. via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code: ```d

Re: issue with static foreach

2021-07-22 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ``` Now, if uncomment those two innocuous commented lines for the if (true == true) block: ```d labelSwitch: switch (lstrExchangeID) { static foreach (sstrExchangeID; gstrExchangeIDs) { mixin(r"case r"d, `"`,

Re: issue with static foreach

2021-07-21 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code: ```d unittest { mixin("{"); mixin("}"); } ``` https://d

issue with static foreach

2021-07-21 Thread someone via Digitalmars-d-learn
The following code chunk compiles perfectly: ```d labelSwitch: switch (lstrExchangeID) { static foreach (sstrExchangeID; gstrExchangeIDs) { mixin(r"case r"d, `"`, sstrExchangeID, `"`, r"d : "d); mixin(r"classTickerCustom"d, sstrExchangeID, r&

Re: static foreach over constant range in @nogc block

2020-10-03 Thread tspike via Digitalmars-d-learn
am not Timon Gehr, the person who originally replied to you, but I was able to find the bug report by searching Bugzilla for "static foreach nogc". Sorry about getting your name wrong, I got a little overzealous when snipping off the quoted part of my post! If I find anything el

Re: static foreach over constant range in @nogc block

2020-10-03 Thread tspike via Digitalmars-d-learn
On Saturday, 3 October 2020 at 14:12:21 UTC, Paul Backus wrote: https://issues.dlang.org/show_bug.cgi?id=18439 Perfect! Thanks for getting back to me so quickly.

Re: static foreach over constant range in @nogc block

2020-10-03 Thread Paul Backus via Digitalmars-d-learn
, but I was able to find the bug report by searching Bugzilla for "static foreach nogc".

Re: static foreach over constant range in @nogc block

2020-10-03 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 3 October 2020 at 14:02:08 UTC, tspike wrote: On Saturday, 3 October 2020 at 12:43:01 UTC, Timon Gehr wrote: It's a compiler bug, the same as this one: @nogc: void main(){ static immutable x = { int[] a; a~=1; return a; }(); } Ah, thank you for the quick reply! Do you know i

Re: static foreach over constant range in @nogc block

2020-10-03 Thread tspike via Digitalmars-d-learn
On Saturday, 3 October 2020 at 12:43:01 UTC, Timon Gehr wrote: It's a compiler bug, the same as this one: @nogc: void main(){ static immutable x = { int[] a; a~=1; return a; }(); } Ah, thank you for the quick reply! Do you know if this bug has already been reported?

Re: static foreach over constant range in @nogc block

2020-10-03 Thread Timon Gehr via Digitalmars-d-learn
On 03.10.20 13:18, tspike wrote: I came across an issue recently that I’m a little confused by. The following program fails to compile under LDC and DMD, though it compiles fine under GDC:     @nogc:     void main()     {     static foreach(i; 0 .. 4)     {     pragma

static foreach over constant range in @nogc block

2020-10-03 Thread tspike via Digitalmars-d-learn
I came across an issue recently that I’m a little confused by. The following program fails to compile under LDC and DMD, though it compiles fine under GDC: @nogc: void main() { static foreach(i; 0 .. 4) { pragma(msg, i); } } Both DMD and

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
https://run.dlang.io/is/xiqi4P not pretty :)) but ...

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
On Wednesday, 9 September 2020 at 17:02:26 UTC, visitor wrote: On Friday, 14 February 2020 at 06:41:02 UTC, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); static foreach (idx, field; A) { static if (__traits(compiles, THREELOOP)) {} else { static if (field == 3

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
On Friday, 14 February 2020 at 06:41:02 UTC, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); static foreach (idx, field; A) { static if (__traits(compiles, THREELOOP)) {} else { static if (field == 3) { pragma(msg, "Got a 3!");

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/8/20 9:38 AM, ag0aep6g wrote: On 08.07.20 14:24, Steven Schveighoffer wrote: I solved it for now by extrapolating the inner code into a local template function. But this is definitely an awkward situation for static foreach. FWIW, you can write the extra function like this:     static

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.07.20 14:24, Steven Schveighoffer wrote: I solved it for now by extrapolating the inner code into a local template function. But this is definitely an awkward situation for static foreach. FWIW, you can write the extra function like this: static foreach (T; Types

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
code somewhere else. However it still won't work, because static foreach requires a label for break. So if I fix the loop problem, I will still have a label problem, because I need to label the switch and use labeled breaks on that. This is really an issue with: a) static foreach-ing cas

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/8/20 5:10 AM, cc wrote: I think I ran into similar problems due to the requirement to use a labeled break inside static foreach.  I got around it by defining enums when my target was found and checking if it existed via __traits(compiles) to "ignore" the rest of the loop.

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 02:06:01 UTC, Steven Schveighoffer wrote: Seems simple enough, except that this inner portion is unrolled, and if I have more than one type to run this on, I already have an "innerloop" label defined. Is there a way to define a label using a mixin or something? o

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread cc via Digitalmars-d-learn
labels like: innerloop: while(haveMoreData) switchstmt: switch(nextDataElement) { static foreach(name; __traits(allMembers, T)) { case name: ... // handle it break switchstmt; } case "STOP": break innerloop; } Seems simple e

Re: constructing labels for static foreach inside switch inside foreach

2020-07-07 Thread bauss via Digitalmars-d-learn
labels like: innerloop: while(haveMoreData) switchstmt: switch(nextDataElement) { static foreach(name; __traits(allMembers, T)) { case name: ... // handle it break switchstmt; } case "STOP": break innerloop; } Seems simple e

constructing labels for static foreach inside switch inside foreach

2020-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
struct a switch that can handle member names (this is for serialization). If I encounter a certain name, then I want to break out of the inner loop (it's a while loop) So naturally, I have to use break statements with labels like: innerloop: while(haveMoreData) switchstmt: switch(n

Re: static foreach / How to construct concatenated string?

2020-03-09 Thread MoonlightSentinel via Digitalmars-d-learn
static and it will work too. Yesh, I forgot about the old implicit static foreach loop.

Re: static foreach / How to construct concatenated string?

2020-03-09 Thread Timon Gehr via Digitalmars-d-learn
On 07.03.20 17:41, MoonlightSentinel wrote: On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote: Is this possible at all? You can use an anonymous lambda to build the string in CTFE: It turns out that if you do use this standard idiom, you might end up getting blamed for an unr

Re: static foreach / How to construct concatenated string?

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 16:41:47 +, MoonlightSentinel said: You can use an anonymous lambda to build the string in CTFE: -- struct S { int a; bool b; } import std; enum string sql = { string s = "CREATE TABLE data("; static

Re: static foreach / How to construct concatenated string?

2020-03-08 Thread Robert M. Münch via Digitalmars-d-learn
; } import std; enum string sql = { string s = "CREATE TABLE data("; static foreach(f; FieldNameTuple!S) { s ~= f ~ ","; } s ~= ");"; return s; } (); pragma(msg, sql); -- This prints "CRE

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 16:40:15 +, Adam D. Ruppe said: Use regular foreach with a regular string. Put that inside a function. Then simply use that function to initialize your other thing and enjoy the magic of CTFE! Perfect! This implicit CTFE is a tricky thing to see/remember/... Feeling a bit

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote: Which of course doesn't work... I didn't find any reference how to build-up strings in a statif foreach loop. Is this possible at all? Use regular foreach with a regular string. Put that inside a function. Then simply use th

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread MoonlightSentinel via Digitalmars-d-learn
REATE TABLE data("; static foreach(f; FieldNameTuple!S) { s ~= f ~ ","; } s ~= ");"; return s; } (); pragma(msg, sql); -- This prints "CREATE TABLE data(a, b);"

static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
I want to create a "CREATE TABLE data (...)" where the columns are derived from struct member names. Something like: string s = "CREATE TABLE data("; static foreach(f; FieldNameTuple!myStruct) { s ~= f ~ ","; } s ~= ");"; Which of course doesn'

Re: static foreach over enum symbols

2020-02-15 Thread Boris Carvajal via Digitalmars-d-learn
On Friday, 14 February 2020 at 22:24:14 UTC, Ben Jones wrote: Hi all, I'm getting unexpected results while trying to process symbols from a module, some of which are enums. Depending on whether or not I comment out the first static foreach loop below, fullyQualifiedName gives me diff

Re: static foreach over enum symbols

2020-02-15 Thread Boris Carvajal via Digitalmars-d-learn
On Friday, 14 February 2020 at 22:24:14 UTC, Ben Jones wrote: Hi all, I'm getting unexpected results while trying to process symbols from a module, some of which are enums. Depending on whether or not I comment out the first static foreach loop below, fullyQualifiedName gives me diff

static foreach over enum symbols

2020-02-14 Thread Ben Jones via Digitalmars-d-learn
Hi all, I'm getting unexpected results while trying to process symbols from a module, some of which are enums. Depending on whether or not I comment out the first static foreach loop below, fullyQualifiedName gives me different results in the second loop. In either case, I'm s

Re: How to use labeled break in static foreach?

2020-02-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/14/20 1:41 AM, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) {     pragma(msg, "Got a 3!");     break THREELOOP; } static if (idx == A.length - 1) {     static assert(0,

Re: How to use labeled break in static foreach?

2020-02-14 Thread Adam D. Ruppe via Digitalmars-d-learn
this kind of thing doesn't work super well due to the nature of compile time. My suggestion is to put the checks and the implementation in separate things. void foo(T...)() { static bool checkHelper() { bool passed; static foreach(t; T) { static if

Re: How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
6, 7]); static foreach (ai, af; ARRS) { static if (!__traits(compiles, FOUND)) { static foreach (idx, field; af.x) { // Have to declare a different MISMATCH enum for each inner loop iteration // unless we enclose it in its own {} scope, but if we do

How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) { pragma(msg, "Got a 3!"); break THREELOOP; } static if (idx == A.length - 1) { static assert(0,

Re: Why does `static foreach` lead to something calling `~=` internally?

2019-07-09 Thread Exil via Digitalmars-d-learn
On Sunday, 7 July 2019 at 18:45:14 UTC, 0xEAB wrote: On Sunday, 7 July 2019 at 16:51:57 UTC, 0xEAB wrote: Why does this `static foreach` lead to hidden usage of operator Further notes by Dan (aka "Wild"): I added some small printfs to the compiler, http://ix.io/1NWM It seems like

Re: Why does `static foreach` lead to something calling `~=` internally?

2019-07-07 Thread 0xEAB via Digitalmars-d-learn
On Sunday, 7 July 2019 at 16:51:57 UTC, 0xEAB wrote: Why does this `static foreach` lead to hidden usage of operator Further notes by Dan (aka "Wild"): I added some small printfs to the compiler, http://ix.io/1NWM It seems like it lowers it into something weird

Re: Why does `static foreach` lead to something calling `~=` internally?

2019-07-07 Thread a11e99z via Digitalmars-d-learn
On Sunday, 7 July 2019 at 17:07:59 UTC, a11e99z wrote: On Sunday, 7 July 2019 at 16:51:57 UTC, 0xEAB wrote: Why does this `static foreach` lead to hidden usage of operator `~=` calls in some cases? probably same oops! this one https://forum.dlang.org/post/eidpgqohllwmuumxw

Re: Why does `static foreach` lead to something calling `~=` internally?

2019-07-07 Thread a11e99z via Digitalmars-d-learn
On Sunday, 7 July 2019 at 16:51:57 UTC, 0xEAB wrote: Why does this `static foreach` lead to hidden usage of operator `~=` calls in some cases? probably same https://forum.dlang.org/post/qd9ee0$2eud$1...@digitalmars.com

Why does `static foreach` lead to something calling `~=` internally?

2019-07-07 Thread 0xEAB via Digitalmars-d-learn
Why does this `static foreach` lead to hidden usage of operator `~=` calls in some cases? static foreach(i; 0 .. cnt) onlineapp.d(9): Error: cannot use operator ~= in @nogc delegate onlineapp.xv!(myUDA("/")).__funcliteral2.__lambda1 import std.traits; private @safe pure not

Re: [TWiD] static foreach loop variable

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
Ok, thanks for explaining. Nice idea.

Re: [TWiD] static foreach loop variable

2019-05-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 28 May 2019 at 13:43:45 UTC, Nick Treleaven wrote: Hi, Last week's TWiD had a tip that didn't make sense: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_05_20.html#tip-of-the-week template Locals(int i) { alias Whatever = int; } static foreach(i; [1, 2, 3]) {

[TWiD] static foreach loop variable

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
Hi, Last week's TWiD had a tip that didn't make sense: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_05_20.html#tip-of-the-week template Locals(int i) { alias Whatever = int; } static foreach(i; [1, 2, 3]) { Locals!i.Whatever; } The body is just `int;`. Not sure how to

Re: dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread Seb via Digitalmars-d-learn
On Monday, 11 February 2019 at 01:05:05 UTC, kdevel wrote: On Monday, 11 February 2019 at 00:54:27 UTC, Seb wrote: On Monday, 11 February 2019 at 00:19:02 UTC, kdevel wrote: [...] You can't read or list files at compile-time. dmd can read files at compile time using the import function [1]

Re: dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread kdevel via Digitalmars-d-learn
files = mixin(LS); static foreach (f; template_files) { pragma (msg, `reading template <` ~ f ~ ">"); template_map[f] = import (f); } } ``` [1] https://forum.dlang.org/thread/njnwacxnvxlwlpjcu...@forum.dlang.org

Re: dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread Jonathan M Davis via Digitalmars-d-learn
mplate_map; > > static this () > { > static foreach (f; dirEntries (``, `*.html`, > SpanMode.shallow)) { >pragma (msg, `reading template <` ~ f ~ ">"); >template_map[f] = import (f); > } > } > ``` > > dmd v2.082.0 says > > ...li

Re: dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread Seb via Digitalmars-d-learn
On Monday, 11 February 2019 at 00:19:02 UTC, kdevel wrote: I am trying to get this code compiled: ```TemplateStore.d module TemplateStore; import std.path; import std.conv; import std.file; [...] You can't read or list files at compile-time. What are you trying to do?

dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code

2019-02-10 Thread kdevel via Digitalmars-d-learn
I am trying to get this code compiled: ```TemplateStore.d module TemplateStore; import std.path; import std.conv; import std.file; immutable string[string] template_map; static this () { static foreach (f; dirEntries (``, `*.html`, SpanMode.shallow)) { pragma (msg, `reading template

Re: static foreach not working with this

2019-01-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 January 2019 at 16:31:49 UTC, Steven Schveighoffer wrote: On 1/7/19 11:16 AM, Michelle Long wrote: On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: [...] static foreach(k, p; AliasSeq!(Alias!this, s)) {{     p.foo(); // Fails even if this line is removed }} To

Re: static foreach not working with this

2019-01-07 Thread Michelle Long via Digitalmars-d-learn
On Monday, 7 January 2019 at 16:29:25 UTC, Alex wrote: On Monday, 7 January 2019 at 16:16:57 UTC, Michelle Long wrote: On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: static foreach(k, p; AliasSeq!(this, s)) {{ p.foo(); // Fails even if this line is removed

Re: static foreach not working with this

2019-01-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/7/19 11:16 AM, Michelle Long wrote: On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: static foreach(k, p; AliasSeq!(this, s)) {{     p.foo(); // Fails even if this line is removed }} this not known at compile time. replace s with this and it works! s is an argument which

Re: static foreach not working with this

2019-01-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 January 2019 at 16:16:57 UTC, Michelle Long wrote: On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: static foreach(k, p; AliasSeq!(this, s)) {{ p.foo(); // Fails even if this line is removed }} this not known at compile time. replace s with this

Re: static foreach not working with this

2019-01-07 Thread Michelle Long via Digitalmars-d-learn
On Monday, 7 January 2019 at 16:01:50 UTC, Michelle Long wrote: static foreach(k, p; AliasSeq!(this, s)) {{ p.foo(); // Fails even if this line is removed }} this not known at compile time. replace s with this and it works! s is an argument which is also not known at

static foreach not working with this

2019-01-07 Thread Michelle Long via Digitalmars-d-learn
static foreach(k, p; AliasSeq!(this, s)) {{ p.foo(); // Fails even if this line is removed }} this not known at compile time. replace s with this and it works! s is an argument which is also not known at compile time(generally). Should work with this. Just "simpli

Re: static foreach direct use of variables

2019-01-01 Thread Michelle Long via Digitalmars-d-learn
On Tuesday, 1 January 2019 at 21:34:08 UTC, Paul Backus wrote: On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote: auto foo(S s) { static foreach(k, p; [s, this]) for(int i = 0; i < p.length; i++) ... } The idea is to provide sin

Re: static foreach direct use of variables

2019-01-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote: auto foo(S s) { static foreach(k, p; [s, this]) for(int i = 0; i < p.length; i++) ... } The idea is to provide single for loop structure for each of the variables(in this case s

Re: static foreach direct use of variables

2019-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote: auto foo(S s) { static foreach(k, p; [s, this]) for(int i = 0; i < p.length; i++) ... } try static foreach(...) {{ stuff }} The double {{ and double }} are intentional.

static foreach direct use of variables

2019-01-01 Thread Michelle Long via Digitalmars-d-learn
auto foo(S s) { static foreach(k, p; [s, this]) for(int i = 0; i < p.length; i++) ... } The idea is to provide single for loop structure for each of the variables(in this case s and this). The is to avoid string mixins which are pathetic

Re: static foreach

2018-10-10 Thread Neia Neutuladh via Digitalmars-d-learn
On 10/10/2018 04:03 PM, James Japherson wrote:> Says that it cannot interpret X(the class that contains the static> opApply). It's a bit hard to diagnose the problem you're getting using that function when we don't have the code that uses it. Or the context that's referenced with the foreach loo

static foreach

2018-10-10 Thread James Japherson via Digitalmars-d-learn
X."~m~");"); } } return 0; } This is not a problem using foreach. But when I use static foreach it fails!!! Says that it cannot interpret X(the class that contains the static opApply). the opApply is static, it does everything at compile time, so why

Re: Static foreach internal variable

2018-08-30 Thread Andrey via Digitalmars-d-learn
On Thursday, 30 August 2018 at 09:49:15 UTC, drug wrote: 30.08.2018 11:19, Andrey пишет: Thanks everybody. Works!

Re: Static foreach internal variable

2018-08-30 Thread drug via Digitalmars-d-learn
30.08.2018 11:19, Andrey пишет: Hello, is it possible to declare an internal variable in "static foreach" and on each iteration assign something to it? Example: static foreach(arg; SomeAliasSeq) {    internal = arg[0].converted;    // a shortcut for expression "arg[0].convert

Re: Static foreach internal variable

2018-08-30 Thread Basile B. via Digitalmars-d-learn
On Thursday, 30 August 2018 at 08:19:47 UTC, Andrey wrote: Hello, is it possible to declare an internal variable in "static foreach" and on each iteration assign something to it? Example: static foreach(arg; SomeAliasSeq) { internal = arg[0].converted;// a shortcut for expre

Static foreach internal variable

2018-08-30 Thread Andrey via Digitalmars-d-learn
Hello, is it possible to declare an internal variable in "static foreach" and on each iteration assign something to it? Example: static foreach(arg; SomeAliasSeq) { internal = arg[0].converted;// a shortcut for expression "arg[0].converted" static if(

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:41:54 UTC, Alex wrote: On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: [...] Would labelling help? https://run.dlang.io/is/vE1KyD Ah! Okay, now I see. Thanks Alex and Adam!

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: switch(foo) Put the label on the switch whatever: switch(foo) mixin(format(" case Foo.%s:bar = Bar.%s;break; ", f, f)); then use the label here break whatever;

Re: mixin break; in switch containing static foreach

2018-04-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm wrote: My base problem is that I want to mixin `break` into a switch statement, but the mixin is within a static foreach. Take a look at the following code: switch(foo) { static foreach(f; EnumMembers!Foo

mixin break; in switch containing static foreach

2018-04-03 Thread Vladimirs Nordholm via Digitalmars-d-learn
My base problem is that I want to mixin `break` into a switch statement, but the mixin is within a static foreach. Take a look at the following code: switch(foo) { static foreach(f; EnumMembers!Foo) { mixin(format(" case Foo.%s:bar

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 23:42:26 UTC, Simen Kjærås wrote: On Wednesday, 28 March 2018 at 23:02:53 UTC, Chris Katko wrote: There's many things that can be done to make the code easier to follow. These lines: [...] [...] WOW. Thank you. That's the kind of tricks for (or more properly:

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 23:02:53 UTC, Chris Katko wrote: There's many things that can be done to make the code easier to follow. These lines: static if (!hasPosition) { assert(0, "Need to pass a position!"); } Can be replaced with thi

  1   2   >