Struct Constructor Lazy
Jiyan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 12 04:00:54 PDT 2017
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, 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!).
Im pretty new to D, can somebody tell me how i would do this?
Is this(lazy int i){ ... a solution?
More information about the Digitalmars-d-learn
mailing list