compile-time initialization of objects need?
Weed
resume755 at mail.ru
Sun Dec 28 02:08:15 PST 2008
Christopher Wright пишет:
> Weed wrote:
>> In fact, the D is not contain a mechanism for compile-time
>> initialization of objects. Maybe add?
>> void main()
>> {
>> S a = S(8); // ok
>> static S b = S(8); // error
>> }
>
> You want syntactic sugar for two things:
>
> // example 1
> void foo ()
> {
> static S s;
> static bool s_initialized = false;
> if (!s_initialized)
> {
> s_initialized = true;
> s = S(8);
> }
> }
>
> // example 2
> // module/class level
> S s;
> static this ()
> {
> s = S(8);
> }
>
>
> Neither of these need to happen at compile time.
It not syntactic sugar. I suggest not to waste time at all performance
on run-time initialization of objects and check of side conditions on a
course of performance of the program.
More information about the Digitalmars-d
mailing list