Re: Getting the initial value of a class field in compile time.

2020-02-09 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 02:25:56 UTC, Steven Schveighoffer wrote: On 2/8/20 7:39 PM, realhet wrote: On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Yea, I exactly ran into that "init" problem, I will avoid that, thx!

Re: Getting the initial value of a class field in compile time.

2020-02-09 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 01:19:55 UTC, Paul Backus wrote: On Sunday, 9 February 2020 at 00:57:05 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe enum initValue = (new

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/8/20 7:39 PM, realhet wrote: On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Hello, class A{   int i = 42; } Is there a way to get that 42? (Input is the class A and the name of the field 'i') A.i.init returns 0, so

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:57:05 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: Using what I've learned: class A{ int i=42; void init(){ // reInitialize class fields alias T =

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:57:05 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: mixin([FieldNameTuple!T].map!(n => n~"=(new T)."~n~";").join); After checking it in the asm debugger, it

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: Using what I've learned: class A{ int i=42; void init(){ // reInitialize class fields alias T = typeof(this); mixin([FieldNameTuple!T].map!(n => n~"=(new

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: classinfo.m_init can be an option, but maybe there's a nicer way to do this? eh the initializer i think is the best. you can sometimes shortcut it pragma(msg, (new

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Hello, class A{ int i = 42; } Is there a way to get that 42? (Input is the class A and the name of the field 'i') A.i.init returns 0, so it doesn't care about the class.

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: classinfo.m_init can be an option, but maybe there's a nicer way to do this? eh the initializer i think is the best. you can sometimes shortcut it pragma(msg, (new A).i); which will call the ctor at ctfe and get the value. but if

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread Drug via Digitalmars-d-learn
On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Hello, class A{ int i = 42; } Is there a way to get that 42? (Input is the class A and the name of the field 'i') A.i.init returns 0, so it doesn't care about the class. classinfo.m_init can be an option, but maybe there's a