Re: Struct Constructor Lazy

2017-07-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:18:08 UTC, Biotronic wrote: The traditional solution is static opCall: That's bug city... the dummy argument is better, or a named static factory function. Foo foo = Foo; Foo foo = Foo(); those are different with static opCall. It also conflicts with

Re: Struct Constructor Lazy

2017-07-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:57:33 UTC, Biotronic wrote: Debug = no optimization. That's not really true, you can have an optimized debug build. dmd's -debug, -g, and -O switches are all independent. -debug turns on blocks labeled with the `debug` switch in code. -g adds info for a

Re: Struct Constructor Lazy

2017-07-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:00:54 UTC, Jiyan wrote: when A(0) is called I would want here optimal performance, so there doesnt even need to be a value pushed on the stack (i=0), what would be like having a constructor with zero arguments (i is never used!). This is so, so irrelevant.

Re: Struct Constructor Lazy

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:02:37 UTC, Jiyan wrote: Thank you, one last question: If i declare the parameter as ref i, then there shouldnt be any overhead wouldnt it? Thanks :) That would be basically the exact equivalent - instead of passing an int, you'll be passing a pointer. --

Re: Struct Constructor Lazy

2017-07-12 Thread Jiyan via Digitalmars-d-learn
Thank you, one last question: If i declare the parameter as ref i, then there shouldnt be any overhead wouldnt it? Thanks :)

Re: Struct Constructor Lazy

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:34:45 UTC, Jiyan wrote: Hey, yes i did but to be honest i used dmd in debug version. The thing about the static one, is that it creates a local object A isnt that a performance issue itself - or am i wrong - im confused actually :P? Debug = no optimization.

Re: Struct Constructor Lazy

2017-07-12 Thread Jiyan via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:18:08 UTC, Biotronic wrote: On Wednesday, 12 July 2017 at 11:00:54 UTC, Jiyan wrote: [...] The traditional solution is static opCall: struct A { int field; static A opCall() { A result; result.field = getDataFromFile("file.txt");

Re: Struct Constructor Lazy

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:00:54 UTC, Jiyan wrote: Hey there:) i want to know whether the following is somehow possible: structs dont have default constructors, i know so: struct A { int field; this(int i){field = getDataFromFile("file.txt");} } A instance = A(0); Here comes my issue:

Struct Constructor Lazy

2017-07-12 Thread Jiyan via Digitalmars-d-learn
Hey there:) i want to know whether the following is somehow possible: structs dont have default constructors, i know so: struct A { int field; this(int i){field = getDataFromFile("file.txt");} } A instance = A(0); Here comes my issue: when A(0) is called I would want here optimal performance,