digitalmars.D.learn - struct inheritance need?
- Weed (20/20) Dec 16 2008 I should explain why it's important for me:
- Bill Baxter (24/24) Dec 16 2008 MjAwOC8xMi8xNiBXZWVkIDxyZXN1bWU3NTVAbWFpbC5ydT46Cj4gSSBzaG91bGQgZXhwbGFp...
- Weed (4/37) Dec 16 2008 necessarily need the ability to change the size of the matrix
- Weed (8/34) Dec 16 2008 I think could help a static creation objects of classes (including
- bearophile (6/8) Dec 16 2008 Inheritance of structs: I think it's not planned. Structs in D are meant...
- Weed (15/25) Dec 16 2008 meant to be used for different things than classes.
- Yigal Chripun (22/50) Dec 16 2008 If I understand you correctly - I think you confuse here two separate
- Weed (10/37) Dec 16 2008 I agree.
- Kagamin (2/9) Dec 17 2008 If you want to use full blown OOP, class is your choise. There are stati...
- Weed (3/14) Dec 17 2008 There does not need a static initialization of static members of the
- Weed (4/20) Dec 17 2008 ===========
- Kagamin (2/4) Dec 18 2008 Well, these objects should be placed in some static variables, right? St...
- Weed (5/15) Dec 18 2008 Yes, static variables of class are initialized with static constructor
- Kagamin (2/6) Dec 18 2008 So your problem is solved.
- Kagamin (1/1) Dec 18 2008 Well, the wish to place an object at specific location is not a problem,...
- Weed (5/12) Dec 18 2008 If everything was so simple! :)
- Weed (4/18) Dec 18 2008 *It* just fills the static variables of class. These variables are
- Kagamin (23/35) Dec 18 2008 Static constructor can execute any valid D statements including construc...
- Weed (3/43) Dec 18 2008 The static constructor does not take *this*. Therefore, it can not
- Kagamin (3/4) Dec 18 2008 You have a trouble with terminology here.
- naryl (2/29) Dec 18 2008 I think the problem with that is that if you have a lot of functions eve...
- Kagamin (7/8) Dec 18 2008 Haa?..
- Derek Parnell (10/11) Dec 18 2008 A static constructor (also known as the Module constructor) executes at
- Weed (2/12) Dec 18 2008 It is exactly
- Kagamin (2/4) Dec 19 2008 So do C++ static object constructors. Though C++ has syntax sugar, which...
- Sergey Gromov (6/13) Dec 19 2008 C++ static object constructors execute at run time except for trivial
- Kagamin (3/5) Dec 21 2008 Although I think it's not guaranteed to work this way and compiler decid...
- Sergey Gromov (8/20) Dec 22 2008 Actually, static constructors are *guaranteed* to run at run time,
- Derek Parnell (7/13) Dec 19 2008 That's nice I suppose, but I don't think that this is what Weed is talki...
- Kagamin (2/3) Dec 21 2008 Sure he wants. From my point of view, this technique is supposed to be a...
- Weed (3/8) Dec 21 2008 please read it thread:
- Kagamin (2/6) Dec 21 2008 The problem of matrix of arbitrary size is solved by size-agnostic base ...
- Weed (3/10) Dec 21 2008 If 2 predetermined matrix certain size multiplied, the produced matrix
- Weed (6/21) Dec 21 2008 ...and a matrix of static size in the same used in other objects -
- Kagamin (2/3) Dec 22 2008 Well... if you want to template every piece of your code, this can cause...
- Weed (8/18) Dec 22 2008 Only for really used combinations (i am using "duck typing" inside
- Kagamin (2/7) Dec 23 2008 I see no way, how it can help.
- Kagamin (2/7) Dec 23 2008 And I see no problem. Absence of compile-time object creation doesn't pr...
- Weed (14/22) Dec 23 2008 The problem is not in use templates.
- Kagamin (4/15) Dec 23 2008 I'm sure any properly formalized problem is solvable. All you need is pr...
- Weed (2/23) Dec 23 2008 Sometimes it is the only way to avoid a large number of global ad
- Weed (10/40) Dec 24 2008 In fact, the minimum number of matrices 3:
- Denis Koroskin (51/56) Dec 21 2008 Ok, here is a problem out of my head:
- Kagamin (7/17) Dec 22 2008 You initialize member field here. It's usually done in instance construc...
- Denis Koroskin (16/36) Dec 22 2008 I don't agree with you. If so, then why we have the following syntax all...
- Kagamin (2/8) Dec 23 2008 It fits well into .init feature. If you want to split constructor, some ...
- Janderson (24/50) Dec 17 2008 The classical approach is to have "helper" template functions.
- Weed (10/71) Dec 17 2008 If I create struct MatrixStruct for compile-time matrix and class
- Christopher Wright (3/11) Dec 17 2008 What operations do you need at compile time and what operations do you
- Weed (4/16) Dec 17 2008 Compile-time creation an object of class or (most likely wrong) struct
- Weed (3/21) Dec 17 2008 You can read this in the digitalmars.D, topic:
- Christopher Wright (3/7) Dec 18 2008 You aren't providing a use case, though. Why not show an example (actual...
- Sergey Gromov (2/10) Dec 19 2008 static invariant Identity = new Matrix([[1,0,0], [0,1,0], [0,0,1]]);
- Christopher Wright (3/14) Dec 20 2008 Okay, do you want to access that matrix in a template? Is there a reason...
- Denis Koroskin (8/21) Dec 20 2008 Let's say, there is an IMatrix interface and its implementations, such a...
- Christopher Wright (8/33) Dec 20 2008 Score! We finally have a use case! I thought there would be a reasonable...
- Janderson (17/97) Dec 17 2008 I'm not sure what you mean:
- Weed (5/113) Dec 17 2008 How do you implement matrix data of this class in compile-time in the
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
Dec 16 2008
MjAwOC8xMi8xNiBXZWVkIDxyZXN1bWU3NTVAbWFpbC5ydT46Cj4gSSBzaG91bGQgZXhwbGFpbiB3 aHkgaXQncyBpbXBvcnRhbnQgZm9yIG1lOgo+Cj4gRm9yIGV4YW1wbGUsIEkgYW0gbWFraW5nIGEg bWF0cml4IG9iamVjdChzKQo+Cj4gSXQgc2hvdWxkIGJlOgo+IC0gYW55IHNpemUKPiAtIHdpdGgg YWJpbGl0eSBvZiBtYWtpbmcgbWF0cml4IGluc3RhbmNlIG9mIGEgZ2l2ZW4gc2l6ZSBpbiBjb21w aWxlIHRpbWUuCj4gLSBhYmlsaXR5IG9mIGNyZWF0aW5nIG1hdHJpeCBpbnN0YW5jZSBpbiBydW50 aW1lLgo+Cj4gSSBoYXZlIGRlY2lkZWQgdG8gbWFrZSBpdCBzdHJ1Y3QgYmVjYXVzZSBJIG5lZWQg dG8gY3JlYXRlIG1hdHJpeAo+IG9iamVjdCBpbiBjb21waWxlIHRpbWUuIGluIHJlYWwgcHJvZ3Jh bSBJJ2xsIG5lZWQgbWF0cmljaWVzIG9mCj4gdmFyaWFibGUgc2l6ZSBhbmQgM8gxLCAzyDMsIDbI NiwgM8g2IHNpemVzIChhbmQgbWF5IGJlIG90aGVyKS4KPgo+IEkgd2FudCB0byBtYWtlIG1hdHJp eCB0ZW1wbGF0ZSBhbmQgaW5zZXJ0IGluIGl0IHdpdGggbWl4aW4gb3BlcmF0b3IKPiBzZXZlcmFs IHN0cnVjdHVyZXMgb2YgZGlmZmVyZW50IHNpemVzIChhbmQgdGhpcyBzdHJ1Y3RzIGFyZSBub3Qg c3RvcmUgaGlzCj4gZGltZW5zaW9ucyBpbiBlYWNoIGluc3RhbmNlLCBvZiBjb3Vyc2U6IHZhcmlh YmxlcyB3aWR0aCBhbmQgaGVpZ2h0IGRlY2xhcmVkCj4gYXMgaW52YXJpYW50KS4gQnkgZG9pbmcg dGhpcyBJJ2xsIGdldCBzZXZlcmFsIGRpZmZlcmVudCBzdHJ1Y3R1cmVzCj4gIChtYXRyaXhfZHlu YW1pYywgbWF0cml4M3gzLCBtYXRyaXg2eDYgZXRjKQo+Cj4gcXVlc3Rpb24gaXMgaG93IHRob3Nl IG1hdHJpY2llcyBjYW4gaW50ZXJvcGVyYXRlPyBUaGV5IGRvZXMgbm90IGhhdmUKPiBjb21tb24g cGFyZW50IChzdHJ1Y3R1cmVzIGRvZXMgbm90IGhhdmUgaW5oZXJpdGFuY2UpICwgc28gSSBjYW4n dAo+IG1ha2UgY29tbW9uIGZ1bmN0aW9uIGZvciBtYXRyaWNpZXMgb2YgZGlmZmVyZW50IHNpemVz IG9wQWRkIGZvcgo+IGV4YW1wbGUsIGFuZCBoYXZlIHRvIGRvIGZ1bmN0aW9ucyBmb3IgYWxsIHR5 cGVzIG9mIG1hdHJpY2llcy4KPgo+IEhvdyBzaG91bGQgSSBpbXBsZW1lbnQgc3VjaCBhIGNsYXNz IEluIEQgcHJvcGVybHk/Cj4gSXQgcG9zc2libGUgaW4gQysrLCBidXQgSSBsaWtlIHNvbWUgb2Yg dGhlIGxhbmd1YWdlIEQKPgoKSGVyZSdzIG9uZSB3YXk6Cmh0dHA6Ly93d3cuZHNvdXJjZS5vcmcv cHJvamVjdHMvb3Blbm1lc2hkL2Jyb3dzZXIvdHJ1bmsvTGluQWxnL2xpbmFsZy9NYXRyaXhULmQK Ci0tYmIK
Dec 16 2008
Bill Baxter пишет:2008/12/16 Weed <resume755 mail.ru>:necessarily need the ability to change the size of the matrix together with a static matrix it can be done using two types of matrices with a single parent.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 DHere's one way: http://www.dsource.org/projects/openmeshd/browser/trunk/LinAlg/linalg/MatrixT.d --bb
Dec 16 2008
Weed пишет: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 DI think could help a static creation objects of classes (including compile-time creation), but it is also impossible now. For example: MatrixClass a(3,2); static MatrixClass a(3,2); Planned in the future to implement inheritance of structs or the static creation of classes?
Dec 16 2008
Weed:Planned in the future to implement inheritance of structs or the static creation of classes?Inheritance of structs: I think it's not planned. Structs in D are meant to be used for different things than classes. Yet, as time passes structs are gaining more power: you can't believe that very recently they have gained constructors/destructors too in D2. Probably in a system language conceptual purity isn't much appreciated :-) Static creation of classes (I think you mean creation of objects): it sounds like an interesting thing, I know of a system language that allows the creation of objects only at compile-time, and at compile-time it also performs several space optimizations among such objects (and such space optimizations often improve running speed a little). Bye, bearophile
Dec 16 2008
bearophile пишет:Weed:static creation of classes?Planned in the future to implement inheritance of structs or theInheritance of structs: I think it's not planned. Structs in D aremeant to be used for different things than classes.Yet, as time passes structs are gaining more power: you can't believethat very recently they have gained constructors/destructors too in D2. Probably in a system language conceptual purity isn't much appreciated :-)I believe that the opportunity to place an object in memory, stack or heap is more important than the struggle against "splicing". allocation of memory by a small object + its using and the use of a a specialist in the design of compilers :))Static creation of classes (I think you mean creation of objects): it sounds like an interesting thing, I know of a system language that allows the creation of objects only at compile-time, and at compile-time it also performs several space optimizations among such objects (and such space optimizations often improve running speed a little).And in fact we come to making structs and classes similar except that classes can not be assigned by value. Such an option I like.
Dec 16 2008
Weed wrote:bearophile пишет: > Weed: >> Planned in the future to implement inheritance of structs or the static creation of classes? > > Inheritance of structs: I think it's not planned. Structs in D are meant to be used for different things than classes. > Yet, as time passes structs are gaining more power: you can't believe > that very recently they have gained constructors/destructors too in D2. Probably in a system language conceptual purity isn't much appreciated :-) > I believe that the opportunity to place an object in memory, stack or heap is more important than the struggle against "splicing". allocation of memory by a small object + its using and the use of a a specialist in the design of compilers :)) > Static creation of classes (I think you mean creation of objects): it > sounds like an interesting thing, I know of a system language that > allows the creation of objects only at compile-time, and at > compile-time it also performs several space optimizations among such > objects (and such space optimizations often improve running speed a > little). And in fact we come to making structs and classes similar except that classes can not be assigned by value. Such an option I like.If I understand you correctly - I think you confuse here two separate and orthogonal issues. 1) struct vs. class 2) memory allocation What D tries to do is to provide types with value semantics via structs and types with reference semantics _and_polymorphism_ via classes. IMO C++ is a prime example how to not design a language and the slicing problem is a good example of that. value types should not have polymorphism whatsoever as is done in D. memory allocation is orthogonal to this: class C {...} Struct S {...} auto c1 = new C; // classes default to heap alloc scope c2 = new C; // c2 is on stack S s1; // structs default to stack auto s2 = new S; // s2 is S* (heap alloc) I think Andrei said he wants to make changes to "scope", that is IIRC. struct inheritance, if it gets implemented in D, should express IMO semantics similar to concepts as in C++0x, not provide polymorphism for value types which is clearly a mistake. (also this will remove the need for typedefs, isn't it?)
Dec 16 2008
Yigal Chripun пишет:If I understand you correctly - I think you confuse here two separate and orthogonal issues. 1) struct vs. class 2) memory allocation What D tries to do is to provide types with value semantics via structs and types with reference semantics _and_polymorphism_ via classes. IMO C++ is a prime example how to not design a language and the slicing problem is a good example of that. value types should not have polymorphism whatsoever as is done in D. memory allocation is orthogonal to this: class C {...} Struct S {...} auto c1 = new C; // classes default to heap alloc scope c2 = new C; // c2 is on stack S s1; // structs default to stack auto s2 = new S; // s2 is S* (heap alloc) I think Andrei said he wants to make changes to "scope", that is IIRC.What will change?struct inheritance, if it gets implemented in D, should express IMO semantics similar to concepts as in C++0x, not provide polymorphism for value types which is clearly a mistake. (also this will remove the need for typedefs, isn't it?)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. Nothing prevents this change?
Dec 16 2008
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.
Dec 17 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.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.
Dec 17 2008
Weed пишет:Kagamin пишет:=========== Now what? How to initiate the procedure for adding this feature?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.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.
Dec 17 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.
Dec 18 2008
Kagamin пишет:Weed Wrote:YesThere 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.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?
Dec 18 2008
Weed Wrote:So your problem is solved.Global variables are static members of module, wich is similar to class and also has static constructor.So what?
Dec 18 2008
Well, the wish to place an object at specific location is not a problem, it's a wish.
Dec 18 2008
Kagamin пишет:Weed Wrote:If everything was so simple! :) Once again: the static constructor of class NOT constructs an object. He just fills the static variables of class. These variables are common to all objects of class.So your problem is solved.Global variables are static members of module, wich is similar to class and also has static constructor.So what?
Dec 18 2008
Weed пишет:Kagamin пишет:*It* just fills the static variables of class. These variables are common to all objects of class. sorry:)Weed Wrote:If everything was so simple! :) Once again: the static constructor of class NOT constructs an object. He just fills the static variables of class. These variables are common to all objects of class.So your problem is solved.Global variables are static members of module, wich is similar to class and also has static constructor.So what?
Dec 18 2008
Weed Wrote:Kagamin пишет:Static constructor can execute any valid D statements including construction of objects. This works: --- import std.stdio; class Matrix { int i; this(int j) { i=j; } } Matrix m; static this() { m=new Matrix(7); } void main() { writeln(m.i); } ---Weed Wrote:If everything was so simple! :) Once again: the static constructor of class NOT constructs an object.So your problem is solved.Global variables are static members of module, wich is similar to class and also has static constructor.So what?
Dec 18 2008
Kagamin пишет:Weed Wrote:The static constructor does not take *this*. Therefore, it can not create instance of object. In your case it initiates the external variable.Kagamin пишет:Static constructor can execute any valid D statements including construction of objects.Weed Wrote:If everything was so simple! :) Once again: the static constructor of class NOT constructs an object.So your problem is solved.Global variables are static members of module, wich is similar to class and also has static constructor.So what?This works: --- import std.stdio; class Matrix { int i; this(int j) { i=j; } } Matrix m; static this() { m=new Matrix(7); } void main() { writeln(m.i); } ---
Dec 18 2008
Weed Wrote:Therefore, it can not create instance of object.You have a trouble with terminology here. In my example m=new Matrix(7); creates an instance of Matrix class.
Dec 18 2008
Kagamin Wrote:Static constructor can execute any valid D statements including construction of objects. This works: --- import std.stdio; class Matrix { int i; this(int j) { i=j; } } Matrix m; static this() { m=new Matrix(7); } void main() { writeln(m.i); } ---I think the problem with that is that if you have a lot of functions every one of which needs a static instance of the same class you'll need to maintain a list of static objects in the static constructor. Weed wants every object to be declared in the function where it is needed.
Dec 18 2008
naryl Wrote:Weed wants every object to be declared in the function where it is needed.Haa?.. void main() { Matrix m=new Matrix(7); writeln(m.i); }
Dec 18 2008
On Thu, 18 Dec 2008 07:24:34 -0500, Kagamin wrote:Static constructor can execute any valid D statements including construction of objects.A static constructor (also known as the Module constructor) executes at program run-time and not at program compile-time. I think Weed wants the ability to have the compiler build class objects at compile-time such that when a program first starts running, the objects are already fully formed in RAM just waiting to be used. -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Dec 18 2008
Derek Parnell пишет:On Thu, 18 Dec 2008 07:24:34 -0500, Kagamin wrote:It is exactlyStatic constructor can execute any valid D statements including construction of objects.A static constructor (also known as the Module constructor) executes at program run-time and not at program compile-time. I think Weed wants the ability to have the compiler build class objects at compile-time such that when a program first starts running, the objects are already fully formed in RAM just waiting to be used.
Dec 18 2008
Derek Parnell Wrote:A static constructor (also known as the Module constructor) executes at program run-time and not at program compile-time.So do C++ static object constructors. Though C++ has syntax sugar, which helps writing declaration and initialization at the same place.
Dec 19 2008
Fri, 19 Dec 2008 04:07:40 -0500, Kagamin wrote:Derek Parnell Wrote:C++ static object constructors execute at run time except for trivial cases. Essentially C++ provides a sugar for static Foo var; static this() { var = new Foo(); } I wonder if D could do this as well.A static constructor (also known as the Module constructor) executes at program run-time and not at program compile-time.So do C++ static object constructors. Though C++ has syntax sugar, which helps writing declaration and initialization at the same place.
Dec 19 2008
Sergey Gromov Wrote:C++ static object constructors execute at run time except for trivial cases.Although I think it's not guaranteed to work this way and compiler decides when to execute constructor. So code should be ready for run-time evaluation. And as code evolves those constructors can switch back and forth between ct and rt evaluation. ps I know a C++ programmer, he wanted to control manually, in what order static object constructors are called :)
Dec 21 2008
Sun, 21 Dec 2008 12:04:42 -0500, Kagamin wrote:Sergey Gromov Wrote:Actually, static constructors are *guaranteed* to run at run time, before main(). Compiler *may* optimize them out and convert into initialized DATA if there are no side effects, that is, if optimized program works exactly as if all static ctors were executed at run time. C++ guarantees that static ctors are executed in order they appear in a module. There is no guarantee about the order in which different modules are initialized though.C++ static object constructors execute at run time except for trivial cases.Although I think it's not guaranteed to work this way and compiler decides when to execute constructor. So code should be ready for run-time evaluation. And as code evolves those constructors can switch back and forth between ct and rt evaluation. ps I know a C++ programmer, he wanted to control manually, in what order static object constructors are called :)
Dec 22 2008
On Fri, 19 Dec 2008 04:07:40 -0500, Kagamin wrote:Derek Parnell Wrote:That's nice I suppose, but I don't think that this is what Weed is talking about. I think he wants to have some objects constructed at compile-time. -- Derek Parnell Melbourne, Australia skype: derek.j.parnellA static constructor (also known as the Module constructor) executes at program run-time and not at program compile-time.So do C++ static object constructors. Though C++ has syntax sugar, which helps writing declaration and initialization at the same place.
Dec 19 2008
Derek Parnell Wrote:I think he wants to have some objects constructed at compile-time.Sure he wants. From my point of view, this technique is supposed to be a means to solve some problem rather than problem itself. But this problem was not put.
Dec 21 2008
Kagamin пишет:Derek Parnell Wrote:please read it thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=80945I think he wants to have some objects constructed at compile-time.Sure he wants. From my point of view, this technique is supposed to be a means to solve some problem rather than problem itself. But this problem was not put.
Dec 21 2008
Weed Wrote:The problem of matrix of arbitrary size is solved by size-agnostic base class whose interface is very similar to that of dynamic matrix.Sure he wants. From my point of view, this technique is supposed to be a means to solve some problem rather than problem itself. But this problem was not put.please read it thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=80945
Dec 21 2008
Kagamin пишет:Weed Wrote:If 2 predetermined matrix certain size multiplied, the produced matrix must be a certain size rather than dynamic.The problem of matrix of arbitrary size is solved by size-agnostic base class whose interface is very similar to that of dynamic matrix.Sure he wants. From my point of view, this technique is supposed to be a means to solve some problem rather than problem itself. But this problem was not put.please read it thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=80945
Dec 21 2008
Weed пишет:Kagamin пишет:...and a matrix of static size in the same used in other objects - matrix functional mixed into this objects by mixin. that is, suppose that after some action should get a matrix matrix3x1 You can not assign it to "pixel" struct, you will receive matrix3x1 and make copy of "pixel".Weed Wrote:If 2 predetermined matrix certain size multiplied, the produced matrix must be a certain size rather than dynamic.The problem of matrix of arbitrary size is solved by size-agnostic base class whose interface is very similar to that of dynamic matrix.Sure he wants. From my point of view, this technique is supposed to be a means to solve some problem rather than problem itself. But this problem was not put.please read it thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmar .D&article_id=80945
Dec 21 2008
Weed Wrote:that is, suppose that after some action should get a matrix matrix3x1Well... if you want to template every piece of your code, this can cause disaster, so I think, this is not very good design. For example, multiplication method will be duplicated N*N*N times for all possible matrix size combinations. I'd prefer run-time checks, though templates can be used for sure.
Dec 22 2008
Kagamin пишет:Weed Wrote:Only for really used combinations (i am using "duck typing" inside templates). In any case, unused functions in the resulting file is not included.that is, suppose that after some action should get a matrix matrix3x1Well... if you want to template every piece of your code, this can cause disaster, so I think, this is not very good design. For example, multiplication method will be duplicated N*N*N times for all possible matrix size combinations.I'd prefer run-time checks, though templates can be used for sure.This problem would help solve the availability of inheritance for structs or compile-time creation of class instances. But now the compiler can identify duplicate parts of the code, working with the same types
Dec 22 2008
Weed Wrote:I see no way, how it can help.I'd prefer run-time checks, though templates can be used for sure.This problem would help solve the availability of inheritance for structs or compile-time creation of class instances.
Dec 23 2008
Weed Wrote:And I see no problem. Absence of compile-time object creation doesn't prevent you from using templates.I'd prefer run-time checks, though templates can be used for sure.This problem would help solve the availability of inheritance for structs or compile-time creation of class instances.
Dec 23 2008
Kagamin пишет:Weed Wrote:The problem is not in use templates. Templates are implementing some of the functionality of 2 types of structures matrices (normal and dynamic). But the structures do not inherit, then to add functionality matrix to other entities ( "pixel", "image" etc) sites will have their list in a template return type. For example: http://www.dsource.org/projects/openmeshd/browser/trunk/LinAlg/linalg/MatrixT.d see template MultReturnType(ArgT) It contain list of all types (MatrixT and VectorT) for return. Will it add types of "image" and "pixel" and still others if needed. This is as good as manually implement a new object model. It is not necessary to suggest to wrap up "pixel" in a class - then it too cannot be initialized in a compile time.And I see no problem. Absence of compile-time object creation doesn't prevent you from using templates.I'd prefer run-time checks, though templates can be used for sure.This problem would help solve the availability of inheritance for structs or compile-time creation of class instances.
Dec 23 2008
Weed Wrote:The problem is not in use templates. Templates are implementing some of the functionality of 2 types of structures matrices (normal and dynamic). But the structures do not inherit, then to add functionality matrix to other entities ( "pixel", "image" etc) sites will have their list in a template return type.If structs don't suit you, don't use them. Classes are better suited for OOP as I said long ago and continue repeating it over and over.It contain list of all types (MatrixT and VectorT) for return. Will it add types of "image" and "pixel" and still others if needed. This is as good as manually implement a new object model.I'm sure any properly formalized problem is solvable. All you need is proper formalization and some design work.It is not necessary to suggest to wrap up "pixel" in a class - then it too cannot be initialized in a compile time.Sure it can't. Does it cause that big problems?
Dec 23 2008
Kagamin пишет:Weed Wrote:Sometimes it is the only way to avoid a large number of global adThe problem is not in use templates. Templates are implementing some of the functionality of 2 types of structures matrices (normal and dynamic). But the structures do not inherit, then to add functionality matrix to other entities ( "pixel", "image" etc) sites will have their list in a template return type.If structs don't suit you, don't use them. Classes are better suited for OOP as I said long ago and continue repeating it over and over.It contain list of all types (MatrixT and VectorT) for return. Will it add types of "image" and "pixel" and still others if needed. This is as good as manually implement a new object model.I'm sure any properly formalized problem is solvable. All you need is proper formalization and some design work.It is not necessary to suggest to wrap up "pixel" in a class - then it too cannot be initialized in a compile time.Sure it can't. Does it cause that big problems?
Dec 23 2008
Weed Wrote:In D module variables can be protected by access modifiers and become module-local.Sometimes it is the only way to avoid a large number of global adIt is not necessary to suggest to wrap up "pixel" in a class - then it too cannot be initialized in a compile time.Sure it can't. Does it cause that big problems?
Dec 24 2008
Kagamin пишет:Weed Wrote:Module full of mathematics turns into horror quite quickly. I have checked this:)In D module variables can be protected by access modifiers and become module-local.Sometimes it is the only way to avoid a large number of global adIt is not necessary to suggest to wrap up "pixel" in a class - then it too cannot be initialized in a compile time.Sure it can't. Does it cause that big problems?
Dec 24 2008
Weed Wrote:If you have troubles with understanding big modules, you can split them into smaller modules, which will be easier to understand for sure.Module full of mathematics turns into horror quite quickly. I have checked this:)In D module variables can be protected by access modifiers and become module-local.Sometimes it is the only way to avoid a large number of global adtoo cannot be initialized in a compile time.Sure it can't. Does it cause that big problems?
Dec 24 2008
Kagamin пишет:Weed Wrote:If you do not want to initialize repeatedly matrix inside the sub, which often cause each other, must be static matrices or declared as global (in relation to these procedures). You agree with that? Do you propose through mixin divide the code into parts? You do not think that it is better to add to language that would give 100% to use the opportunity of calculations at compile time. This greatly simplify the code and perfectly and logically fit into the language.If you have troubles with understanding big modules, you can split them into smaller modules, which will be easier to understand for sure.Module full of mathematics turns into horror quite quickly. I have checked this:)In D module variables can be protected by access modifiers and become module-local.Sometimes it is the only way to avoid a large number of global adtoo cannot be initialized in a compile time.Sure it can't. Does it cause that big problems?
Dec 24 2008
Weed Wrote:If you do not want to initialize repeatedly matrix inside the sub, which often cause each other, must be static matrices or declared as global (in relation to these procedures). You agree with that?What's problem? If you want static or global variables, you have them in D.Do you propose through mixin divide the code into parts?Well, why mixin? Just create different modules and place code according to its purpose to these modules.You do not think that it is better to add to language that would give 100% to use the opportunity of calculations at compile time. This greatly simplify the code and perfectly and logically fit into the language.Compile-time evaluation is just an optimization technique, which may or may not be applied without any change to source code, so it doesn't affect source code in any way, it just can't. In C++ you can't tell whether the code executes at compile time, as as of standard, it's completely up to the compiler to optimize code generation.
Dec 25 2008
Kagamin пишет:Weed Wrote:Yeah, right. I propose that it be expanded to optimize the static arrays and classes.If you do not want to initialize repeatedly matrix inside the sub, which often cause each other, must be static matrices or declared as global (in relation to these procedures). You agree with that?What's problem? If you want static or global variables, you have them in D.Do you propose through mixin divide the code into parts?Well, why mixin? Just create different modules and place code according to its purpose to these modules.You do not think that it is better to add to language that would give 100% to use the opportunity of calculations at compile time. This greatly simplify the code and perfectly and logically fit into the language.Compile-time evaluation is just an optimization technique, which may or may not be applied without any change to source code, so it doesn't affect source code in any way, it just can't. In C++ you can't tell whether the code executes at compile time, as as of standard, it's completely up to the compiler to optimize code generation.
Dec 25 2008
Kagamin пишет:Weed Wrote:Incidentally, this is incorrect. In the event that it is impossible to calculate the static expression compiler immediately gives an error rather than moves calculation to run-time.If you do not want to initialize repeatedly matrix inside the sub, which often cause each other, must be static matrices or declared as global (in relation to these procedures). You agree with that?What's problem? If you want static or global variables, you have them in D.Do you propose through mixin divide the code into parts?Well, why mixin? Just create different modules and place code according to its purpose to these modules.You do not think that it is better to add to language that would give 100% to use the opportunity of calculations at compile time. This greatly simplify the code and perfectly and logically fit into the language.Compile-time evaluation is just an optimization technique, which may or may not be applied without any change to source code,
Dec 25 2008
Weed пишет:Kagamin пишет:In fact, the minimum number of matrices 3: dynamic fixed-size fixed-size static The last 2 are different way of storing components - "fixed-size static" has dynamic array (because compile-time assignment is now does not assign anything to static array) and "fixed-size" it with a static array with size calculated in the template. I will be happy if someone tells a mistake in the design of my idea :)Weed Wrote:The problem is not in use templates. Templates are implementing some of the functionality of 2 types of structures matrices (normal and dynamic). But the structures do not inherit, then to add functionality matrix to other entities ( "pixel", "image" etc) sites will have their list in a template return type. For example: http://www.dsource.org/projects/openmeshd/browser/trunk/Lin lg/linalg/MatrixT.d see template MultReturnType(ArgT) It contain list of all types (MatrixT and VectorT) for return. Will it add types of "image" and "pixel" and still others if needed. This is as good as manually implement a new object model. It is not necessary to suggest to wrap up "pixel" in a class - then it too cannot be initialized in a compile time.And I see no problem. Absence of compile-time object creation doesn't prevent you from using templates.I'd prefer run-time checks, though templates can be used for sure.This problem would help solve the availability of inheritance for structs or compile-time creation of class instances.
Dec 24 2008
On Sun, 21 Dec 2008 19:34:52 +0300, Kagamin <spam here.lot> wrote:Derek Parnell Wrote:Ok, here is a problem out of my head: Let's say we have a GUI application with Widgets and WidgetFactories. Each widget is initialized with a *valid* pointer to some WidgetFactory (a dummy one, perhaps) to avoid "if (factory !is null) factory.doSomething();" checks (for example). Our first try: import std.stdio; struct WidgetFactory { int someParameterValue = 42; } WidgetFactory defaultFactory = { 14 }; class Widget { WidgetFactory* factory = &defaultFactory; } void main() { Widget w = new Widget(); writefln(w.factory.someParameterValue); // prints 14 } It works, because memory for global structs is reserved at compile time and pointer to it is also a known compile-time expression. Let's go further and see if we can replace a struct with a class instance: WidgetFactory defaultFactory; class Widget { WidgetFactory factory = defaultFactory; } This code compiles but doesn't work as we need. Another try: WidgetFactory defaultFactory; static this() { defaultFactory = new StubFactory(); } class Widget { WidgetFactory* factory = &defaultFactory; } Works as we need but we now have to dereference a pointer twice. A better solution would be to have the following: WidgetFactory defaultFactory = new StubFactory(); class Widget { WidgetFactory factory = defaultFactory; } A memory for 'defaultFactory' is reserved at compile-time whereas a ctor is ran at run-time (similar to "static this" construct). In fact, allowing reference type to created at compile time would eliminate most of the needs for static this. The following construct: Foo foo; static this() { foo = new Foo(); } could be replaced with Foo foo = new Foo(); which behaves just the same but is shorter, nicier, easier to write and read (undestand).I think he wants to have some objects constructed at compile-time.Sure he wants. From my point of view, this technique is supposed to be a means to solve some problem rather than problem itself. But this problem was not put.
Dec 21 2008
Denis Koroskin Wrote:class Widget { WidgetFactory* factory = &defaultFactory; } void main() { Widget w = new Widget(); writefln(w.factory.someParameterValue); // prints 14 }You initialize member field here. It's usually done in instance constructor. class Widget { WidgetFactory factory; this(){ factory = defaultFactory; } }
Dec 22 2008
Kagamin Wrote:Denis Koroskin Wrote:I don't agree with you. If so, then why we have the following syntax allowed: class Foo { int i = 42; } if we could just use class Foo { this() { i = 42; } } ? Imagine you have lots of ctors (with different arguments), should you put i = 42; into every one? Or move it into some initialize() method? Don't you think it is too verbose?class Widget { WidgetFactory* factory = &defaultFactory; } void main() { Widget w = new Widget(); writefln(w.factory.someParameterValue); // prints 14 }You initialize member field here. It's usually done in instance constructor. class Widget { WidgetFactory factory; this(){ factory = defaultFactory; } }
Dec 22 2008
Denis Koroskin Wrote:I don't agree with you. If so, then why we have the following syntax allowed: class Foo { int i = 42; }It fits well into .init feature. If you want to split constructor, some subtle bugs can arise. For example one programmer stumbled into such bug in Java: base class constructor was called, it called virtual method, overriden in derived class, this method assigned an object to a field, then base class constructor returned and derived field initializers were called and they assigned null to that field, so object ended up with null in the field.
Dec 23 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 DThe 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
Dec 17 2008
Janderson пишет: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? : ))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 DThe 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()... }Also, interfaces can not be used with the structsclass 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
Dec 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?
Dec 17 2008
Christopher Wright пишет:Weed wrote:Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterIf 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?
Dec 17 2008
Weed пишет:Christopher Wright пишет:You can read this in the digitalmars.D, topic: Feature request: Deploying a class instance in the default data segmentWeed wrote:Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterIf 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?
Dec 17 2008
Weed wrote:Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterYou aren't providing a use case, though. Why not show an example (actual code) of what you would do if you had this ability?
Dec 18 2008
Thu, 18 Dec 2008 18:36:07 -0500, Christopher Wright wrote:Weed wrote:static invariant Identity = new Matrix([[1,0,0], [0,1,0], [0,0,1]]);Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterYou aren't providing a use case, though. Why not show an example (actual code) of what you would do if you had this ability?
Dec 19 2008
Sergey Gromov wrote:Thu, 18 Dec 2008 18:36:07 -0500, Christopher Wright wrote:Okay, do you want to access that matrix in a template? Is there a reason it can't be a struct?Weed wrote:static invariant Identity = new Matrix([[1,0,0], [0,1,0], [0,0,1]]);Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterYou aren't providing a use case, though. Why not show an example (actual code) of what you would do if you had this ability?
Dec 20 2008
On Sat, 20 Dec 2008 16:46:44 +0300, Christopher Wright <dhasenan gmail.com> wrote:Sergey Gromov wrote:Let's say, there is an IMatrix interface and its implementations, such as SparseMatrix, RowMajor/ColumnMajorMatrix etc. class IdentityMatrix : IMatrix { public float at(int row, int col) { return (row == col) ? 1 : 0; } }Thu, 18 Dec 2008 18:36:07 -0500, Christopher Wright wrote:Okay, do you want to access that matrix in a template? Is there a reason it can't be a struct?Weed wrote:static invariant Identity = new Matrix([[1,0,0], [0,1,0], [0,0,1]]);Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterYou aren't providing a use case, though. Why not show an example (actual code) of what you would do if you had this ability?
Dec 20 2008
Denis Koroskin wrote:On Sat, 20 Dec 2008 16:46:44 +0300, Christopher Wright <dhasenan gmail.com> wrote:Score! We finally have a use case! I thought there would be a reasonable use case, but I couldn't come up with one off the top of my head. The workaround would be to use a struct at compile time and convert to an appropriate class when necessary. This is a rather ugly workaround; it takes a fair bit of time at runtime and increases executable sizes (I don't think you could do a sparse matrix at compile time, for instance -- you would need dynamic allocation for that).Sergey Gromov wrote:Let's say, there is an IMatrix interface and its implementations, such as SparseMatrix, RowMajor/ColumnMajorMatrix etc. class IdentityMatrix : IMatrix { public float at(int row, int col) { return (row == col) ? 1 : 0; } }Thu, 18 Dec 2008 18:36:07 -0500, Christopher Wright wrote:Okay, do you want to access that matrix in a template? Is there a reason it can't be a struct?Weed wrote:static invariant Identity = new Matrix([[1,0,0], [0,1,0], [0,0,1]]);Compile-time creation an object of class or (most likely wrong) struct inheritance. I have prepared a distinct feature request and send it laterYou aren't providing a use case, though. Why not show an example (actual code) of what you would do if you had this ability?
Dec 20 2008
Weed wrote:Janderson пишет: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.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? : ))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 DThe 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()... }Also, interfaces can not be used with the structsclass 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
Dec 17 2008
Janderson пишет:Weed wrote: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?Janderson пишет: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.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? : ))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 DThe 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()... }Also, interfaces can not be used with the structsclass 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
Dec 17 2008