Re: Can Enums be integral types?

2022-04-19 Thread Manfred Nowak via Digitalmars-d-learn
On Sunday, 17 April 2022 at 18:25:32 UTC, Bastiaan Veelo wrote: The reason is in [17.1.5](https://dlang.org/spec/enum.html): “EnumBaseType types cannot be implicitly cast to an enum type.” Thy. That's the anchor in the specs preventing Enums to be integral types.

Re: Calling template member function?

2022-04-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/19/22 8:44 PM, Andrey Zherikov wrote: On Tuesday, 19 April 2022 at 20:29:01 UTC, Steven Schveighoffer wrote: You can work around the dual context, if you are OK with passing the second context explicitly. The easiest way is to move the member function to a UFCS function. an example:

Re: Calling template member function?

2022-04-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 20:29:01 UTC, Steven Schveighoffer wrote: You can work around the dual context, if you are OK with passing the second context explicitly. The easiest way is to move the member function to a UFCS function. an example: ```d struct X { int x; void

Re: Calling template member function?

2022-04-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 19:07:37 UTC, Ali Çehreli wrote: On 4/19/22 11:18, Andrey Zherikov wrote: > Is there a way/workaround to achieve the desired behavior? Can you describe the goal a little more. For example, I assume you really need a more useful lambda although the example you

Re: Calling template member function?

2022-04-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/19/22 2:18 PM, Andrey Zherikov wrote: On Tuesday, 19 April 2022 at 16:38:42 UTC, Steven Schveighoffer wrote: On 4/19/22 11:46 AM, Paul Backus wrote: If you remove `static` from `f_new`, you get an error message talking about this explicitly: Interesting that `static` does anything

Re: Calling template member function?

2022-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 4/19/22 11:18, Andrey Zherikov wrote: > Is there a way/workaround to achieve the desired behavior? Can you describe the goal a little more. For example, I assume you really need a more useful lambda although the example you show seems unnecessary: enum dg = () => func(); That lambda

Re: Calling template member function?

2022-04-19 Thread Andrey Zherikov via Digitalmars-d-learn
I get the same error even with just `struct`: ```d struct S { static void f_new(alias func)() { func(); } } void f_new(alias func)() { func(); } void f(FUNC)(FUNC func) { f_new!(() => func()); // works // S.f_new!(() => func()); // doesn't work } ```

Re: Calling template member function?

2022-04-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 18:18:26 UTC, Andrey Zherikov wrote: Is there a way/workaround to achieve the desired behavior? Those two bugs pointed above were reported in 2017 and 2011 (!) which makes me think that they won't be fixed any time soon (I'm not sure that they are actually the same

Re: Calling template member function?

2022-04-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 16:38:42 UTC, Steven Schveighoffer wrote: On 4/19/22 11:46 AM, Paul Backus wrote: If you remove `static` from `f_new`, you get an error message talking about this explicitly: Interesting that `static` does anything there, since it's a no-op. -Steve I put

Re: Beginner memory question.

2022-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 19, 2022 at 05:01:15PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > In linux using zram i've allocated and made a compressed drive of 8Gb > which took only 200k of space [...] All unallocated pages are assumed > null/zero filled, and if you zeroize a block it will

Re: Beginner memory question.

2022-04-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time. This might be very much an OS

Re: Calling template member function?

2022-04-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/19/22 11:46 AM, Paul Backus wrote: On Tuesday, 19 April 2022 at 13:36:26 UTC, Andrey Zherikov wrote: I want to migrate my library API from standalone function that takes delegate as argument to a template member function that takes delegate as a template parameter but compiler errors out.

Re: Calling template member function?

2022-04-19 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 13:36:26 UTC, Andrey Zherikov wrote: I want to migrate my library API from standalone function that takes delegate as argument to a template member function that takes delegate as a template parameter but compiler errors out. Here is code example: ```d import

Re: Can Enums be integral types?

2022-04-19 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 13:20:21 UTC, Bastiaan Veelo wrote: There is nothing that requires enum values to be unique, though: ```d import std; void main() { enum E {Zero = 0, One = 0, Two = 0} writeln(E.Two); // Zero! } ``` True, but if you want it be useful they really need to be

Re: Calling template member function?

2022-04-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/19/22 9:36 AM, Andrey Zherikov wrote: I want to migrate my library API from standalone function that takes delegate as argument to a template member function that takes delegate as a template parameter but compiler errors out. Here is code example: ```d import std.stdio; template T(P) {

Re: save and load a 2d array to a file

2022-04-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/19/22 5:12 AM, Stanislav Blinov wrote: On Tuesday, 19 April 2022 at 06:05:27 UTC, Ali Çehreli wrote: One quirk of rawWrite and rawRead is that they want slices of objects. It is a little awkward when there is just one thing to write and read. Uncompiled but something like this:   int i

Re: Beginner memory question.

2022-04-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 19, 2022 at 12:54:06PM +, bauss via Digitalmars-d-learn wrote: > On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: > > On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: > > > Is virtual memory entering into the equation? > > > > Probably. Memory allocated

Calling template member function?

2022-04-19 Thread Andrey Zherikov via Digitalmars-d-learn
I want to migrate my library API from standalone function that takes delegate as argument to a template member function that takes delegate as a template parameter but compiler errors out. Here is code example: ```d import std.stdio; template T(P) { static void f_new(alias func)() {

Re: Can Enums be integral types?

2022-04-19 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 01:25:13 UTC, Era Scarecrow wrote: The 'integral' or numeric value is used for uniqueness, […] There is nothing that requires enum values to be unique, though: ```d import std; void main() { enum E {Zero = 0, One = 0, Two = 0} writeln(E.Two); // Zero! } ```

Re: Beginner memory question.

2022-04-19 Thread bauss via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time. You can also exceed your RAM in

Re: DUB issues

2022-04-19 Thread bauss via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 09:37:49 UTC, Mike Parker wrote: On Tuesday, 19 April 2022 at 08:58:02 UTC, bauss wrote: On Monday, 18 April 2022 at 13:41:04 UTC, Mike Parker wrote: On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote: Any ideas how to get into contact/fix this issue ?

Re: DUB issues

2022-04-19 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 08:58:02 UTC, bauss wrote: On Monday, 18 April 2022 at 13:41:04 UTC, Mike Parker wrote: On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote: Any ideas how to get into contact/fix this issue ? I've emailed Sönke and pointed him to this thread. Wouldn't

Re: save and load a 2d array to a file

2022-04-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 06:05:27 UTC, Ali Çehreli wrote: One quirk of rawWrite and rawRead is that they want slices of objects. It is a little awkward when there is just one thing to write and read. Uncompiled but something like this: int i = 42; file.rawWrite(*cast((int[1]*)()));

Re: save and load a 2d array to a file

2022-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 4/19/22 01:46, bauss wrote: > However it should be fairly trivial like: > > void rawWriteValue(T)(T value) > { >rawWrite(*cast((T[1]*)())); > } > > Or is there some downside to this that I'm missing? Nonet that I can see. I think I used the following version in actual code (adding the

Re: DUB issues

2022-04-19 Thread bauss via Digitalmars-d-learn
On Monday, 18 April 2022 at 13:41:04 UTC, Mike Parker wrote: On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote: Any ideas how to get into contact/fix this issue ? I've emailed Sönke and pointed him to this thread. Wouldn't the appropriate thing to do be dub being officially a

Re: save and load a 2d array to a file

2022-04-19 Thread bauss via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 06:05:27 UTC, Ali Çehreli wrote: int i = 42; file.rawWrite(*cast((int[1]*)())); // Casted to be an array of 1 I assume since we don't have a rawWriteValue, that it's rarely needed. However it should be fairly trivial like: void rawWriteValue(T)(T

Re: save and load a 2d array to a file

2022-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 4/18/22 22:05, Chris Katko wrote: > D > struct map_t{ > int data[50][50]; > } map; Hey! That's C! :) > //save > std.file.write("save.map", map.data); // compiles That serializes the array byte-by-byte. > //load > map.data = std.file.read("save.map", map.data.sizeof); // error And that