Re: Associative Array with double[][]

2021-07-21 Thread frame via Digitalmars-d-learn
On Thursday, 22 July 2021 at 04:46:13 UTC, frame wrote: Of course a double* makes more sense than a void* type for the AA here.

Re: Associative Array with double[][]

2021-07-21 Thread frame via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:13:14 UTC, seany wrote: If there are multiple possibilities, what is the fastest in terms of memory? Thank you. I believe the fastest way (as seen from your loop) would be using pointer arithmetric and using void* keys for diagonalLengths and an index

Re: enum true, or 1

2021-07-21 Thread Ali Çehreli via Digitalmars-d-learn
On 7/21/21 8:44 PM, Brian Tiffin wrote: > What is the preferred syntax for simple on/off states? I use std.typecons.Flag. It feels very repetitive but that's what we have: import std.typecons; void foo(Flag!"doFilter" doFilter) { if (doFilter) { // ... } } bool someCondition; void

Re: enum true, or 1

2021-07-21 Thread rikki cattermole via Digitalmars-d-learn
On 22/07/2021 3:44 PM, Brian Tiffin wrote: What is the preferred syntax for simple on/off states?  Did I read that D was moving to strictly 1 and 0 literals instead of true/false on/off yes/no? This is the first time I'm hearing about it, so almost certainly no.

Re: enum true, or 1

2021-07-21 Thread Mathias LANG via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:44:13 UTC, Brian Tiffin wrote: What is the preferred syntax for simple on/off states? Did I read that D was moving to strictly 1 and 0 literals instead of true/false on/off yes/no? If so, is there an idiom for yes/no/maybe -1,0,1 less/equal/greater?

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" lobjTicker"d, sstrExchangeID, r" = new

enum true, or 1

2021-07-21 Thread Brian Tiffin via Digitalmars-d-learn
What is the preferred syntax for simple on/off states? Did I read that D was moving to strictly 1 and 0 literals instead of true/false on/off yes/no? If so, is there an idiom for yes/no/maybe -1,0,1 less/equal/greater? Excuse the noise. For some backfill; getting used to DDoc.

Re: Performance issue with fiber

2021-07-21 Thread seany via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote: Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code. [...] Following. I am also in need of more information to increase speed of D binaries using

Associative Array with double[][]

2021-07-21 Thread seany via Digitalmars-d-learn
I have a perimeter of a shape, given by a `double [][]` . I want to keep the lengths of various diagonals in another associative array. So, /// define some associative array to keep track of diagonals here.. auto perimeter = new double[][] (0,0); /// --- fill up perimeter here

Performance issue with fiber

2021-07-21 Thread hanabi1224 via Digitalmars-d-learn
Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code. Basically, I found D lang's logical thread communication is quite like Elixir's (process), I have programs written in both D and Elixir but the D version

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-21 Thread Dukc via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be in that function (the `bool` implementation is pretty simple). -Steve DMD complains about dereferences in three different lines. I suspect it's `this`

Re: Method definition

2021-07-21 Thread Tim Gunesh via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 14:02:42 UTC, Adam D Ruppe wrote: On Wednesday, 21 July 2021 at 13:56:11 UTC, Tim Gunesh wrote: This allows you to quickly understand the content of the class, especially in large undocumented projects. The D compiler can auto-generate listings like that. dmd -H

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/21/21 7:56 AM, apz28 wrote: On Wednesday, 21 July 2021 at 11:52:39 UTC, apz28 wrote: On Wednesday, 21 July 2021 at 04:52:44 UTC, Mathias LANG wrote: It seems the compiler is doing extra analysis and seeing that a null pointer is being dereferenced. Can you provide the code for

Re: Method definition

2021-07-21 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 13:56:11 UTC, Tim Gunesh wrote: This allows you to quickly understand the content of the class, especially in large undocumented projects. The D compiler can auto-generate listings like that. dmd -H makes a .di file with the bodies stripped out you can pursue, or

Re: betterC shared static ctor

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/21/21 5:07 AM, vit wrote: Thanks, it works, but now I have different problem. I need call static method for all instantions of template struct from `crt_constructor`. Is there way to iterate over all instantions of template? Not unless you register them somehow upon instantiation. Or

Re: Method definition

2021-07-21 Thread Tim Gunesh via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 12:08:21 UTC, Tim Gunesh wrote: Is it possible to define methods outside the class in C ++ style? Something like this: ```d class Parent{ void Print(); } void Parent.Print(){ writeln("Hello, D!"); } ``` I was afraid that this is not possible. I'm partly

Re: How to parse a json node that contains children of different types?

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/20/21 11:00 PM, Mathias LANG wrote: But if you take a step back, I think you might find this solution is far from ideal. Having worked on a JSON library myself, I can tell you they are all implemented with a tagged union. And converting a tagged union to a tagged union is no improvement.

Re: Yet another parallel foreach + continue question

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/21 10:58 PM, H. S. Teoh wrote: I didn't check the implementation to verify this, but I'm pretty sure `break`, `continue`, etc., in the parallel foreach body does not change which iteration gets run or not. `break` should be undefined behavior (it is impossible to know which loops

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-21 Thread bauss via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 03:25:03 UTC, apz28 wrote: VisualD project - Any hint to work around DMD version: DMD32 D Compiler v2.096.0-rc.1-dirty Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright Failed Build Command line: dmd -release

Re: Method definition

2021-07-21 Thread bauss via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 12:08:21 UTC, Tim Gunesh wrote: Is it possible to define methods outside the class in C ++ style? Something like this: ```d class Parent{ void Print(); } void Parent.Print(){ writeln("Hello, D!"); } ``` No and it doesn't make much sense to do so. The

Re: Method definition

2021-07-21 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 12:08:21 UTC, Tim Gunesh wrote: Is it possible to define methods outside the class in C ++ style? Something like this: ```d class Parent{ void Print(); } void Parent.Print(){ writeln("Hello, D!"); } ``` No, it's not possible. However, [uniform function

Method definition

2021-07-21 Thread Tim Gunesh via Digitalmars-d-learn
Is it possible to define methods outside the class in C ++ style? Something like this: ```d class Parent{ void Print(); } void Parent.Print(){ writeln("Hello, D!"); } ```

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-21 Thread apz28 via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 11:52:39 UTC, apz28 wrote: On Wednesday, 21 July 2021 at 04:52:44 UTC, Mathias LANG wrote: It seems the compiler is doing extra analysis and seeing that a null pointer is being dereferenced. Can you provide the code for "pham\db\db_skdatabase.d" at L138 through

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-21 Thread apz28 via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 04:52:44 UTC, Mathias LANG wrote: It seems the compiler is doing extra analysis and seeing that a null pointer is being dereferenced. Can you provide the code for "pham\db\db_skdatabase.d" at L138 through 140 ? ```d package(pham.db): // Line# 133

Re: Initializing a complex dynamic array (with real part from one array, and imaginary from other array)?

2021-07-21 Thread drug via Digitalmars-d-learn
I wouldn't state it is the best way but you can try something like that: ```D import std.complex; import std.range : zip; import std.algorithm : equal, map; import std.array : array; void main(){ auto N=2; double[] x,y; x.length = N; y.length = N; x[0] = 1.1; x[1] =

Re: betterC shared static ctor

2021-07-21 Thread vit via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 08:28:22 UTC, Mike Parker wrote: On Wednesday, 21 July 2021 at 08:11:06 UTC, vit wrote: Is it possible to call all shared static ctors in betterC? ```d //-betterC static immutable int i; shared static this(){ i = 42; } extern(C) void main(){ assert(i

Initializing a complex dynamic array (with real part from one array, and imaginary from other array)?

2021-07-21 Thread james.p.leblanc via Digitalmars-d-learn
I am trying to initialize a complex dynamic array, from two strictly real dynamic arrays (one to be the real part, the other to be the imaginary part. Here is simple sample of what I have tried: - import std.stdio; import std.math;

Re: betterC shared static ctor

2021-07-21 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 08:11:06 UTC, vit wrote: Is it possible to call all shared static ctors in betterC? ```d //-betterC static immutable int i; shared static this(){ i = 42; } extern(C) void main(){ assert(i != 42); } ``` These rely on DRuntime, which is not linked in

betterC shared static ctor

2021-07-21 Thread vit via Digitalmars-d-learn
Is it possible to call all shared static ctors in betterC? ```d //-betterC static immutable int i; shared static this(){ i = 42; } extern(C) void main(){ assert(i != 42); } ```

Re: Can static variables in methods be local for each object?

2021-07-21 Thread bauss via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 15:59:30 UTC, Dukc wrote: On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote: Is there a way to make myvar local to each instance of `X` without making it a variable of `X`? Just curious. Yes. ```d import std.stdio; class X { int x(int param) {

Re: How to parse a json node that contains children of different types?

2021-07-21 Thread Bagomot via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 03:00:51 UTC, Mathias LANG wrote: TL;DR: If you want to use loosely typed data in a strongly typed language, you need to come up with a common type. That common type is usually either a discriminated union (which a JSON object is, essentially) or something that is