December 17, 2008
Weed пишет:
> Kagamin пишет:
>> Weed Wrote:
>>
>>> I agree.
>>> In my case I chose to structure rather than a class because it can be initialized at compile time.
>>>
>>> But now I thing must be allowed to deploy class in the default data segment. And add the possibility of creating a object of class at compile time.
>>
>> If you want to use full blown OOP, class is your choise. There are static constructors for static initialization.
> 
> There does not need a static initialization of static members of the class. There must be able to create objects of classes at compile time.


===========
Now what?

How to initiate the procedure for adding this feature?
December 17, 2008
Weed wrote:
> I should explain why it's important for me:
> 
> For example, I am making a matrix object(s)
> 
> It should be:
> - any size
> - with ability of making matrix instance of a given size in compile time.
> - ability of creating matrix instance in runtime.
> 
> I have decided to make it struct because I need to create matrix
> object in compile time. in real program I'll need matricies of
> variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).
> 
> I want to make matrix template and insert in it with mixin operator
> several structures of different sizes (and this structs are not store his dimensions in each instance, of course: variables width and height declared as invariant). By doing this I'll get several different structures  (matrix_dynamic, matrix3x3, matrix6x6 etc)
> 
> question is how those matricies can interoperate? They does not have
> common parent (structures does not have inheritance) , so I can't
> make common function for matricies of different sizes opAdd for
> example, and have to do functions for all types of matricies.
> 
> How should I implement such a class In D properly?     It possible in C++, but I like some of the language D

The classical approach is to have "helper" template functions. Essentially:

void doOpearation(mymatrix)(...)
{

}


Note this is compiletime polymorphisms.

Now if you want to add runtime polymorphism it is impossible to get away from a cost.  You can use a wrapper class like so:

interface CommonMatrix
{
	operation()...
}

class PolymorphicMatrix(mymatrix) : CommonMatrix
{
	operation()...
}

You'll probably find though that PolymorphicMartix should be some higher level concept, like car, or entity.

The great thing about these techniques is that they give a whole load more power then just using inheritance alone because you can essentially attach many different behaviors to that struct.

I hope that was helpful.

-Joel
December 17, 2008
Janderson пишет:
> Weed wrote:
>> I should explain why it's important for me:
>>
>> For example, I am making a matrix object(s)
>>
>> It should be:
>> - any size
>> - with ability of making matrix instance of a given size in compile time.
>> - ability of creating matrix instance in runtime.
>>
>> I have decided to make it struct because I need to create matrix
>> object in compile time. in real program I'll need matricies of
>> variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).
>>
>> I want to make matrix template and insert in it with mixin operator
>> several structures of different sizes (and this structs are not store his dimensions in each instance, of course: variables width and height declared as invariant). By doing this I'll get several different structures  (matrix_dynamic, matrix3x3, matrix6x6 etc)
>>
>> question is how those matricies can interoperate? They does not have
>> common parent (structures does not have inheritance) , so I can't
>> make common function for matricies of different sizes opAdd for
>> example, and have to do functions for all types of matricies.
>>
>> How should I implement such a class In D properly?     It possible in C++, but I like some of the language D
> 
> The classical approach is to have "helper" template functions. Essentially:
> 
> void doOpearation(mymatrix)(...)
> {
> 
> }

If I create struct MatrixStruct for compile-time matrix and class MatrixClass for all other I will not be able to create a function of interaction between these objects through the templates because some of them will be announced before the other and it will not be able to get another type of object in a template.

(I do not know, understand this long phrase on my strange English or not? : ))


> 
> 
> Note this is compiletime polymorphisms.
> 
> Now if you want to add runtime polymorphism it is impossible to get away from a cost.  You can use a wrapper class like so:
> 
> interface CommonMatrix
> {
>     operation()...
> }

	
Also, interfaces can not be used with the structs


> 
> class PolymorphicMatrix(mymatrix) : CommonMatrix
> {
>     operation()...
> }
> 
> You'll probably find though that PolymorphicMartix should be some higher level concept, like car, or entity.
> 
> The great thing about these techniques is that they give a whole load more power then just using inheritance alone because you can essentially attach many different behaviors to that struct.
> 
> I hope that was helpful.
> 
> -Joel
December 17, 2008
Weed wrote:
> If I create struct MatrixStruct for compile-time matrix and class MatrixClass for all other I will not be able to create a function of interaction between these objects through the templates because some of them will be announced before the other and it will not be able to get another type of object in a template.
> 
> (I do not know, understand this long phrase on my strange English or not? : ))

What operations do you need at compile time and what operations do you need at runtime?
December 18, 2008
Christopher Wright пишет:
> Weed wrote:
>> If I create struct MatrixStruct for compile-time matrix and class MatrixClass for all other I will not be able to create a function of interaction between these objects through the templates because some of them will be announced before the other and it will not be able to get another type of object in a template.
>>
>> (I do not know, understand this long phrase on my strange English or not? : ))
> 
> What operations do you need at compile time and what operations do you need at runtime?

Compile-time creation an object of class or (most likely wrong) struct inheritance.

I have prepared a distinct feature request and send it later
December 18, 2008
Weed пишет:
> Christopher Wright пишет:
>> Weed wrote:
>>> If I create struct MatrixStruct for compile-time matrix and class MatrixClass for all other I will not be able to create a function of interaction between these objects through the templates because some of them will be announced before the other and it will not be able to get another type of object in a template.
>>>
>>> (I do not know, understand this long phrase on my strange English or not? : ))
>>
>> What operations do you need at compile time and what operations do you need at runtime?
> 
> Compile-time creation an object of class or (most likely wrong) struct inheritance.
> 
> I have prepared a distinct feature request and send it later

You can read this in the digitalmars.D, topic:
Feature request: Deploying a class instance in the default data segment
December 18, 2008
Weed wrote:
> Janderson пишет:
>> Weed wrote:
>>> I should explain why it's important for me:
>>>
>>> For example, I am making a matrix object(s)
>>>
>>> It should be:
>>> - any size
>>> - with ability of making matrix instance of a given size in compile time.
>>> - ability of creating matrix instance in runtime.
>>>
>>> I have decided to make it struct because I need to create matrix
>>> object in compile time. in real program I'll need matricies of
>>> variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).
>>>
>>> I want to make matrix template and insert in it with mixin operator
>>> several structures of different sizes (and this structs are not store his dimensions in each instance, of course: variables width and height declared as invariant). By doing this I'll get several different structures  (matrix_dynamic, matrix3x3, matrix6x6 etc)
>>>
>>> question is how those matricies can interoperate? They does not have
>>> common parent (structures does not have inheritance) , so I can't
>>> make common function for matricies of different sizes opAdd for
>>> example, and have to do functions for all types of matricies.
>>>
>>> How should I implement such a class In D properly?     It possible in C++, but I like some of the language D
>>
>> The classical approach is to have "helper" template functions. Essentially:
>>
>> void doOpearation(mymatrix)(...)
>> {
>>
>> }
> 
> If I create struct MatrixStruct for compile-time matrix and class MatrixClass for all other I will not be able to create a function of interaction between these objects through the templates because some of them will be announced before the other and it will not be able to get another type of object in a template.
> 
> (I do not know, understand this long phrase on my strange English or not? : ))
> 
> 
>>
>>
>> Note this is compiletime polymorphisms.
>>
>> Now if you want to add runtime polymorphism it is impossible to get away from a cost.  You can use a wrapper class like so:
>>
>> interface CommonMatrix
>> {
>>     operation()...
>> }
> 
>     Also, interfaces can not be used with the structs


I'm not sure what you mean:

I meant this:

You have your struct:

struct Foo
{

}

Then you have your template wrapper

class DoDynamicPolymorpicStuff(T) : TheInterface
{
	T foo;

	operation()
	{
		foo;
	}
}


Its a reasonably common pattern.

> 
> 
>>
>> class PolymorphicMatrix(mymatrix) : CommonMatrix
>> {
>>     operation()...
>> }
>>
>> You'll probably find though that PolymorphicMartix should be some higher level concept, like car, or entity.
>>
>> The great thing about these techniques is that they give a whole load more power then just using inheritance alone because you can essentially attach many different behaviors to that struct.
>>
>> I hope that was helpful.
>>
>> -Joel
December 18, 2008
Janderson пишет:
> Weed wrote:
>> Janderson пишет:
>>> Weed wrote:
>>>> I should explain why it's important for me:
>>>>
>>>> For example, I am making a matrix object(s)
>>>>
>>>> It should be:
>>>> - any size
>>>> - with ability of making matrix instance of a given size in compile time.
>>>> - ability of creating matrix instance in runtime.
>>>>
>>>> I have decided to make it struct because I need to create matrix
>>>> object in compile time. in real program I'll need matricies of
>>>> variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).
>>>>
>>>> I want to make matrix template and insert in it with mixin operator
>>>> several structures of different sizes (and this structs are not store his dimensions in each instance, of course: variables width and height declared as invariant). By doing this I'll get several different structures  (matrix_dynamic, matrix3x3, matrix6x6 etc)
>>>>
>>>> question is how those matricies can interoperate? They does not have
>>>> common parent (structures does not have inheritance) , so I can't
>>>> make common function for matricies of different sizes opAdd for
>>>> example, and have to do functions for all types of matricies.
>>>>
>>>> How should I implement such a class In D properly?     It possible in C++, but I like some of the language D
>>>
>>> The classical approach is to have "helper" template functions. Essentially:
>>>
>>> void doOpearation(mymatrix)(...)
>>> {
>>>
>>> }
>>
>> If I create struct MatrixStruct for compile-time matrix and class MatrixClass for all other I will not be able to create a function of interaction between these objects through the templates because some of them will be announced before the other and it will not be able to get another type of object in a template.
>>
>> (I do not know, understand this long phrase on my strange English or not? : ))
>>
>>
>>>
>>>
>>> Note this is compiletime polymorphisms.
>>>
>>> Now if you want to add runtime polymorphism it is impossible to get away from a cost.  You can use a wrapper class like so:
>>>
>>> interface CommonMatrix
>>> {
>>>     operation()...
>>> }
>>
>>     Also, interfaces can not be used with the structs
> 
> 
> I'm not sure what you mean:
> 
> I meant this:
> 
> You have your struct:
> 
> struct Foo
> {
> 
> }
> 
> Then you have your template wrapper
> 
> class DoDynamicPolymorpicStuff(T) : TheInterface
> {
>     T foo;
> 
>     operation()
>     {
>         foo;
>     }
> }
> 
> 
> Its a reasonably common pattern.
> 

How do you implement matrix data of this class in compile-time in the case of matrix is fixed-sized?

Whether you can start immediately after the program began to operate this class matrix as if it was created at compile time?

>>
>>
>>>
>>> class PolymorphicMatrix(mymatrix) : CommonMatrix
>>> {
>>>     operation()...
>>> }
>>>
>>> You'll probably find though that PolymorphicMartix should be some higher level concept, like car, or entity.
>>>
>>> The great thing about these techniques is that they give a whole load more power then just using inheritance alone because you can essentially attach many different behaviors to that struct.
>>>
>>> I hope that was helpful.
>>>
>>> -Joel
December 18, 2008
Weed Wrote:

> There does not need a static initialization of static members of the class. There must be able to create objects of classes at compile time.

Well, these objects should be placed in some static variables, right? Static variables are initialized with static constructors. Global variables are static members of module, wich is similar to class and also has static constructor.
December 18, 2008
Kagamin пишет:
> Weed Wrote:
> 
>> There does not need a static initialization of static members of the class. There must be able to create objects of classes at compile time.
> 
> Well, these objects should be placed in some static variables,
> right?

Yes

> Static variables are initialized with static constructors.

Yes, static variables of class are initialized with static constructor of class.

> Global variables are static members of module, wich is similar to
> class and also has static constructor.

So what?