Feature request: Deploying a class instance in the default data segment

Weed resume755 at mail.ru
Wed Dec 17 21:05:03 PST 2008


Feature request: Deploying a class instance in the default data segment 
and creation of a class instance at compile time.

In this post I'll try to prove the necessity of this feature.

I have found that in D it is impossible to create a polymorphic object 
(class or struct) which can be created at compile-time.

Good specific example of such an object is a matrix class.

For some matrices it is good to create and initialize them at compile
time, not dynamically at run time.

Also for matrices of predefined size it is wrong to duplicate their
dimensions (their width and height should be declared invariant and,
consequently occupy memory only once)

At the same time dynamically created matrices of arbitrary size which
can be changed at run time are also needed. For example to make a slice 
of giant matrix it's more efficient to modify it in-place than to copy 
it. These matrices have variable width and height.

So we have minimum two types of matrices: dynamic and constant sized 
with ability of compile time initialization. It is necessary to provide
interaction between them (for example overload arithmetic operators
for them). For this purpose it is necessary for them to be inherited
from common parent. So it can not be structures, only classes.

But classes can not be created at compile time.

So I propose to add possibility of deployment of class instance in the 
default data segment and creation of class instance at compile time.



More information about the Digitalmars-d mailing list