How to list aggregate members in order of declaration at compile time?

2016-11-10 Thread Ivan Kazmenko via Digitalmars-d-learn
Hi. I want to somehow list members of a class in the order of their declaration. The immediate goal is to generate a few functions, like the "default" constructor for structs but only with all the fields, or the "reader" function, but I'm interested in the general question as well. I can g

cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Picaud Vincent via Digitalmars-d-learn
Hi All, In my adventure to learn a little bit of D coming from C++ I am now faced with the following problem: I have read about "cross-module overloading", ยง5.5.2 page 146 of Andrei Alexandrescu book. That makes sense to me and this is interesting. As a concrete example here the scenario: I

problem with isnan

2016-11-10 Thread Charles Hixson via Digitalmars-d-learn
The line: assert(isnan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation)); throws the exception: core.exception.AssertError@cell.d(285): cell has unexpected curActivation: nan and I've looked at it backwards and forwards and don't understand why. It's

Class copy

2016-11-10 Thread Satoshi via Digitalmars-d-learn
Hello, how can I copy class when I have pointer to the parent of it? eg. class Foo { int m_a; this(const(Foo) other) { m_a = other.m_a; } } class Bar : Foo { int m_b; this(const(Bar) other) { super(other); m_b = other.m_b; } R dup(this R)(

Re: problem with isnan

2016-11-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 10 November 2016 at 16:41:56 UTC, Charles Hixson wrote: It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion. What am I doing wrong? How did you set it? There are like billions of different NaNs. I'm not

Re: cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 10, 2016 15:46:11 Picaud Vincent via Digitalmars-d- learn wrote: > ---> What am I missing? What is the right way to do that? Honestly, I'm surprised that the compiler let you alias std.algorithm.comparison.min, because it's a templated function, and in the case of templat

Re: Class copy

2016-11-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 10 November 2016 at 16:44:24 UTC, Satoshi wrote: But this implementation of dup doesn't work. The dup will need to be a virtual function in the base class for best results, reimplemented in each child class. You could also copy the bytes using runtime type info... void*

Correct way to create singleton?

2016-11-10 Thread Konstantin Kutsevalov via Digitalmars-d-learn
Hi, what is a correct (and simple) way to create an singleton? This is how I see that now: ``` class ApMessageRouter { static ApMessageRouter instance = null; private this() { } // for disable constructor to use from outside public

Re: Correct way to create singleton?

2016-11-10 Thread Anonymouse via Digitalmars-d-learn
On Thursday, 10 November 2016 at 17:17:51 UTC, Konstantin Kutsevalov wrote: Hi, what is a correct (and simple) way to create an singleton? https://wiki.dlang.org/Low-Lock_Singleton_Pattern

Re: Correct way to create singleton?

2016-11-10 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Thursday, 10 November 2016 at 17:22:48 UTC, Anonymouse wrote: On Thursday, 10 November 2016 at 17:17:51 UTC, Konstantin Kutsevalov wrote: Hi, what is a correct (and simple) way to create an singleton? https://wiki.dlang.org/Low-Lock_Singleton_Pattern great!

Re: cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Picaud Vincent via Digitalmars-d-learn
On Thursday, 10 November 2016 at 17:12:32 UTC, Jonathan M Davis wrote: On Thursday, November 10, 2016 15:46:11 Picaud Vincent via Digitalmars-d- learn wrote: [...] Honestly, I'm surprised that the compiler let you alias std.algorithm.comparison.min, because it's a templated function, and in t

Re: Correct way to create singleton?

2016-11-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/10/16 12:17 PM, Konstantin Kutsevalov wrote: Hi, what is a correct (and simple) way to create an singleton? This is how I see that now: ``` class ApMessageRouter { static ApMessageRouter instance = null; private this() { } // for disable constructor to use from outside p

Re: cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/10/16 12:12 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Thursday, November 10, 2016 15:46:11 Picaud Vincent via Digitalmars-d- learn wrote: ---> What am I missing? What is the right way to do that? Honestly, I'm surprised that the compiler let you alias std.algorithm.compa

Re: cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 10, 2016 14:32:28 Steven Schveighoffer via Digitalmars-d-learn wrote: > On 11/10/16 12:12 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Thursday, November 10, 2016 15:46:11 Picaud Vincent via > > Digitalmars-d- > > > > learn wrote: > >> ---> What am I missing

Re: cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 10, 2016 17:41:02 Picaud Vincent via Digitalmars-d- learn wrote: > It is certainly a compiler problem: I used gdc -> compile error, > but with dmd it compiles and runs fine. Full details in the git > repo. Don't bother with gdc at this point. Unless there's a development vers

Re: Correct way to create singleton?

2016-11-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 10, 2016 14:25:49 Steven Schveighoffer via Digitalmars-d-learn wrote: > There's a specific way to create a singleton that David Simcha outlined > in a talk at dconf 2013, that avoids all the race condition issues that > singletons traditionally have: > > https://davesdprogram

Re: cross_module function overloading & alias & template: how to ?

2016-11-10 Thread Picaud Vincent via Digitalmars-d-learn
On Thursday, 10 November 2016 at 20:12:10 UTC, Jonathan M Davis wrote: On Thursday, November 10, 2016 17:41:02 Picaud Vincent via Digitalmars-d- learn wrote: It is certainly a compiler problem: I used gdc -> compile error, but with dmd it compiles and runs fine. Full details in the git repo.

Re: problem with isnan

2016-11-10 Thread Charles Hixson via Digitalmars-d-learn
On 11/10/2016 08:47 AM, Adam D. Ruppe via Digitalmars-d-learn wrote: On Thursday, 10 November 2016 at 16:41:56 UTC, Charles Hixson wrote: It's *supposed* to be nan, and the assert message reports that it is, but it should pass the assert test, not throw an assertion. What am I doing wrong? H

Re: problem with isnan

2016-11-10 Thread Daniel Kozak via Digitalmars-d-learn
Dne 10.11.2016 v 17:41 Charles Hixson via Digitalmars-d-learn napsal(a): The line: assert(isnan (c.curActivation), "cell has unexpected curActivation: %s".format(c.curActivation)); throws the exception: core.exception.AssertError@cell.d(285): cell has unexpected curActivation: nan an