non-constant expression while initializing two dim array

2020-06-08 Thread tirithen via Digitalmars-d-learn
How can I initialize my two dimensional array? When I try to run the code below I get the error: Error: non-constant expression ["user":[cast(Capability)0], "administrator":[cast(Capability)1]] Code: enum Capability { self, administer } alias Capabilities =

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:13:36 UTC, mw wrote: Hi, I have this program: import std.stdio; void f(ref int[] arr) { arr ~= 3; } void main() { int[][] arrs; int[] arr; foreach (i; 0 .. 3) {

Re: non-constant expression while initializing two dim array

2020-06-08 Thread Basile B. via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:37:18 UTC, tirithen wrote: How can I initialize my two dimensional array? When I try to run the code below I get the error: Error: non-constant expression ["user":[cast(Capability)0], "administrator":[cast(Capability)1]] Code: enum Capability {

Re: `this` template params for struct not expressing constness.

2020-06-08 Thread evilrat via Digitalmars-d-learn
On Monday, 8 June 2020 at 07:35:12 UTC, adnan338 wrote: Hi, as far as I understand, the `this` template parameter includes constness qualifiers as seen in https://ddili.org/ders/d.en/templates_more.html To apply this I have this following struct: module bst; struct Tree(T) { T item;

`this` template params for struct not expressing constness.

2020-06-08 Thread adnan338 via Digitalmars-d-learn
Hi, as far as I understand, the `this` template parameter includes constness qualifiers as seen in https://ddili.org/ders/d.en/templates_more.html To apply this I have this following struct: module bst; struct Tree(T) { T item; Tree!T* parent, left, right; this(T item) {

Re: `this` template params for struct not expressing constness.

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 07:35:12 UTC, adnan338 wrote: Self* searchTree(this Self)(auto in ref T item) const { if ( is null) return null; if (this.item == item) return return (this.item < item) ? this.right.searchTree(item) :

how to append (ref) int[] to int[][]?

2020-06-08 Thread mw via Digitalmars-d-learn
Hi, I have this program: import std.stdio; void f(ref int[] arr) { arr ~= 3; } void main() { int[][] arrs; int[] arr; foreach (i; 0 .. 3) { arr = new int[0]; arrs ~= arr; //(a)

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:42:44 UTC, Simen Kjærås wrote: Arrays (technically, slices) in D are essentially this struct: struct Array(T) { T* ptr; size_t length; // operator overloads } So when you have int[][], each element of the outer array is an Array!int. These, as simple

Re: Mixin and imports

2020-06-08 Thread data pulverizer via Digitalmars-d-learn
On Monday, 8 June 2020 at 02:55:25 UTC, jmh530 wrote: ``` ... template foo(string f) { mixin("alias foo = .foo!(" ~ f ~ ");"); } ... ``` Out of curiosity what does the "." in front of `foo` mean? I've seen that in some D code on the compiler in GitHub and have no idea what it does. I

Re: Mixin and imports

2020-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.06.20 16:27, data pulverizer wrote: Out of curiosity what does the "." in front of `foo` mean? I've seen that in some D code on the compiler in GitHub and have no idea what it does. I tried Googling it to no avail. It doesn't have anything to do with UFCS does it?

Re: Mixin and imports

2020-06-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 8 June 2020 at 02:55:25 UTC, jmh530 wrote: In the code below, foo!fabs compiles without issue, but foo!"fabs" does not because the import is not available in the string mixin. Why do you even want foo!"fabs"? Usually when I see people having this problem it is actually a

Re: Metaprogramming with D

2020-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.06.20 16:41, Jan Hönig wrote: On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: [...]   writeln(q{   void foo() {   }     }); What is the name of this `q` thing? How do i find it? Are there any recent tutorials on it? https://dlang.org/spec/lex.html#token_strings

Re: Metaprogramming with D

2020-06-08 Thread FunkyD via Digitalmars-d-learn
On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: On 6/6/20 5:03 PM, FunkyD wrote:> On Saturday, 6 June 2020 at 09:57:36 UTC, Jan Hönig wrote: > D is pretty good for meta-programming. For certain other things it is > terrible. I am glad I don't know enough about other technologies to

Re: Mixin and imports

2020-06-08 Thread jmh530 via Digitalmars-d-learn
On Monday, 8 June 2020 at 14:27:26 UTC, data pulverizer wrote: [snip] Out of curiosity what does the "." in front of `foo` mean? I've seen that in some D code on the compiler in GitHub and have no idea what it does. I tried Googling it to no avail. It doesn't have anything to do with UFCS

Re: Metaprogramming with D

2020-06-08 Thread Jan Hönig via Digitalmars-d-learn
On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: dmd -mixin= ... thanks for the tip! writeln(q{ void foo() { } }); What is the name of this `q` thing? How do i find it? Are there any recent tutorials on it?

Re: Metaprogramming with D

2020-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 08.06.20 16:45, ag0aep6g wrote: On 08.06.20 16:41, Jan Hönig wrote: On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: [...]   writeln(q{   void foo() {   }     }); What is the name of this `q` thing? How do i find it? Are there any recent tutorials on it?

Re: Metaprogramming with D

2020-06-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 8 June 2020 at 14:41:55 UTC, Jan Hönig wrote: What is the name of this `q` thing? It is just a string that looks like code.

Re: `this` template params for struct not expressing constness.

2020-06-08 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 8 June 2020 at 09:08:40 UTC, adnan338 wrote: On Monday, 8 June 2020 at 08:10:19 UTC, Simen Kjærås wrote: On Monday, 8 June 2020 at 07:35:12 UTC, adnan338 wrote: Self* searchTree(this Self)(auto in ref T item) const { if ( is null) return null; if

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Paul Backus via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:52:36 UTC, mw wrote: On Monday, 8 June 2020 at 06:42:44 UTC, Simen Kjærås wrote: Arrays (technically, slices) in D are essentially this struct: struct Array(T) { T* ptr; size_t length; // operator overloads } So when you have int[][], each element of

Re: `this` template params for struct not expressing constness.

2020-06-08 Thread adnan338 via Digitalmars-d-learn
On Monday, 8 June 2020 at 08:10:19 UTC, Simen Kjærås wrote: On Monday, 8 June 2020 at 07:35:12 UTC, adnan338 wrote: Self* searchTree(this Self)(auto in ref T item) const { if ( is null) return null; if (this.item == item) return return

Re: Mixin and imports

2020-06-08 Thread Paul Backus via Digitalmars-d-learn
On Monday, 8 June 2020 at 10:23:24 UTC, jmh530 wrote: On Monday, 8 June 2020 at 04:13:08 UTC, Mike Parker wrote: [snip] The problem isn't the mixin. It's the template. Templates take the scope of their declaration, not their instantiation. So the mixin is getting the template's scope.

Re: Mixin and imports

2020-06-08 Thread jmh530 via Digitalmars-d-learn
On Monday, 8 June 2020 at 10:28:39 UTC, Paul Backus wrote: [snip] Thanks for that suggestion. That works for me. Unfortunately, it's probably not worth the extra effort though, versus doing foo!fabs in my case.

Re: Mixin and imports

2020-06-08 Thread jmh530 via Digitalmars-d-learn
On Monday, 8 June 2020 at 04:13:08 UTC, Mike Parker wrote: [snip] The problem isn't the mixin. It's the template. Templates take the scope of their declaration, not their instantiation. So the mixin is getting the template's scope. Anyway, this appears to work: `double z =

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread Dukc via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:13:36 UTC, mw wrote: what I really want in (a) is append `ref arr` and output [[3], [3], [3]], i.e. the real `arr` be appended instead of its copy. I tried to change arrs' decl to: (ref (int[]))[] arrs; // the intended semantics I want 1) I'm wondering how

Re: Mixin and imports

2020-06-08 Thread jmh530 via Digitalmars-d-learn
On Monday, 8 June 2020 at 12:20:46 UTC, Adam D. Ruppe wrote: [snip] Why do you even want foo!"fabs"? Usually when I see people having this problem it is actually a misunderstanding of what is possible with the foo!fabs style - which is better in basically every way and can be used in most

Re: Mixin and imports

2020-06-08 Thread FunkyD via Digitalmars-d-learn
On Monday, 8 June 2020 at 10:41:53 UTC, jmh530 wrote: On Monday, 8 June 2020 at 10:28:39 UTC, Paul Backus wrote: [snip] Thanks for that suggestion. That works for me. Unfortunately, it's probably not worth the extra effort though, versus doing foo!fabs in my case. If they are all from

Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread mw via Digitalmars-d-learn
Hi, I'm trying to build this package: https://code.dlang.org/packages/fixed however, the compiler error out: ldc2-1.21.0-linux-x86_64/bin/../import/std/math.d(5783,39): Error: llroundl cannot be interpreted at compile time, because it has no available source code Looks like it does some

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 8 June 2020 at 18:08:57 UTC, mw wrote: 2) even it does so, but why such simple function as lroundl cannot be CTFE-ed? Because, as the error message states, there's no source for it :) std.math calls into C math library.

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 18:43:58 UTC, Stanislav Blinov wrote: On Monday, 8 June 2020 at 18:08:57 UTC, mw wrote: 2) even it does so, but why such simple function as lroundl cannot be CTFE-ed? Because, as the error message states, there's no source for it :) std.math calls into C math

Re: Dub Error Message "Invalid variable: DUB"

2020-06-08 Thread Andre Pany via Digitalmars-d-learn
On Sunday, 7 June 2020 at 16:54:48 UTC, Paul Backus wrote: On Sunday, 7 June 2020 at 16:26:17 UTC, Andre Pany wrote: On Sunday, 7 June 2020 at 15:37:27 UTC, Paul Backus wrote: On Sunday, 7 June 2020 at 12:52:12 UTC, Andre Pany wrote: I am not sure but $DUB is a variable which could be used

Re: Dub Error Message "Invalid variable: DUB"

2020-06-08 Thread Paul Backus via Digitalmars-d-learn
On Monday, 8 June 2020 at 17:55:24 UTC, Andre Pany wrote: I had a second look on the descriptions and from a non native speaker view it sounds correct. But you are right from a native speaker view the wording might be incorrect. If you have time, could you check the wording and make a

Re: Dub Error Message "Invalid variable: DUB"

2020-06-08 Thread Andre Pany via Digitalmars-d-learn
On Monday, 8 June 2020 at 18:38:17 UTC, Paul Backus wrote: On Monday, 8 June 2020 at 17:55:24 UTC, Andre Pany wrote: I had a second look on the descriptions and from a non native speaker view it sounds correct. But you are right from a native speaker view the wording might be incorrect. If

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/8/20 2:08 PM, mw wrote: Hi, I'm trying to build this package: https://code.dlang.org/packages/fixed however, the compiler error out: ldc2-1.21.0-linux-x86_64/bin/../import/std/math.d(5783,39): Error: llroundl cannot be interpreted at compile time, because it has no available source

Re: Mixin and imports

2020-06-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/8/20 11:11 AM, jmh530 wrote: On Monday, 8 June 2020 at 14:27:26 UTC, data pulverizer wrote: [snip] Out of curiosity what does the "." in front of `foo` mean? I've seen that in some D code on the compiler in GitHub and have no idea what it does. I tried Googling it to no avail. It

Re: Mixin and imports

2020-06-08 Thread data pulverizer via Digitalmars-d-learn
On Monday, 8 June 2020 at 16:02:02 UTC, Steven Schveighoffer wrote: On 6/8/20 11:11 AM, jmh530 wrote: On Monday, 8 June 2020 at 14:27:26 UTC, data pulverizer wrote: [snip] Out of curiosity what does the "." in front of `foo` mean? [snip] ag0aep6g provided the link to it [snip] The dot

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/8/20 2:53 PM, mw wrote: And with a symbol-to-c-func table, it should be able to just call that C func. Consider that the libc available to the compiler might not be the same as the libc for the target (e.g. cross compilation). Not just that, but this opens the compiler up to a huge

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 19:05:45 UTC, Steven Schveighoffer wrote: On 6/8/20 2:53 PM, mw wrote: And with a symbol-to-c-func table, it should be able to just call that C func. Consider that the libc available to the compiler might not be the same as the libc for the target (e.g. cross