Re: Variadic Mixin/Template classes?

2017-11-25 Thread Chirs Forest via Digitalmars-d-learn
On Saturday, 25 November 2017 at 10:08:36 UTC, vit wrote: On Saturday, 25 November 2017 at 09:52:01 UTC, Chirs Forest wrote: [...] import std.meta : staticMap; class Bar(T) { T bar; } class Foo(Ts...){ staticMap!(Bar, Ts) bars; this(){ static foreach(i, alias T; Ts) bars

Re: Variadic Mixin/Template classes?

2017-11-25 Thread vit via Digitalmars-d-learn
On Saturday, 25 November 2017 at 09:52:01 UTC, Chirs Forest wrote: I'd like to make a class that takes multiple template types (1 - several) which can hold an array/tuple of a second class that are instantiated with those types. class Bar(T) { T bar; } class Foo(T[]){ // not sure how to t

Variadic Mixin/Template classes?

2017-11-25 Thread Chirs Forest via Digitalmars-d-learn
I'd like to make a class that takes multiple template types (1 - several) which can hold an array/tuple of a second class that are instantiated with those types. class Bar(T) { T bar; } class Foo(T[]){ // not sure how to take variadic types here? Bar!(?)[] bars; //not sure how I'd defi

Re: object.factory with template classes for serializing subclasses automatically

2012-09-10 Thread Jacob Carlborg
On 2012-09-11 07:57, Chris Cain wrote: Ah, I see now. Well regardless, it couldn't be done so conveniently/transparently because Serializable!B wouldn't exist in the binary unless it was actually created in code. Hence proper runtime reflection is needed. I see no way out of this. -- /Jacob

Re: object.factory with template classes for serializing subclasses automatically

2012-09-10 Thread Chris Cain
On Tuesday, 11 September 2012 at 04:47:11 UTC, timotheecour wrote: Also, now that I think about it, why couldn't you do this? (it's equivalent): auto serialize(T)(T a) { auto c = cast(SerializerBase) new Serializer!T; return c.serialize(a); } that won't work with my example: class A{} c

Re: object.factory with template classes for serializing subclasses automatically

2012-09-10 Thread timotheecour
Also, now that I think about it, why couldn't you do this? (it's equivalent): auto serialize(T)(T a) { auto c = cast(SerializerBase) new Serializer!T; return c.serialize(a); } that won't work with my example: class A{} class B:A{int x;} A a=new B; auto c=serialize(a); => T is A, but we

Re: object.factory with template classes for serializing subclasses automatically

2012-09-10 Thread Chris Cain
On Tuesday, 11 September 2012 at 03:18:40 UTC, timotheecour wrote: auto serialize(T)(T a){ auto c=cast(SerializerBase)Object.factory("Serializer!("~typeid(a).to!string~").Serializer"); return c.serialize(a); } Also, now that I think about it, why couldn't you do this? (it's equivalen

Re: object.factory with template classes for serializing subclasses automatically

2012-09-10 Thread Chris Cain
On Tuesday, 11 September 2012 at 03:18:40 UTC, timotheecour wrote: So the question is: is that technically impossible or not to enhance Object.factory in such ways? Unless someone else wants to correct me, I'm going to say technically impossible. Object.factory constructs a class at runtime giv

Re: object.factory with template classes for serializing subclasses automatically

2012-09-10 Thread timotheecour
I don't understand how Object.factory could help with serializing. But what would help is if we did get proper runtime reflection. All that'd be needed would be to have Object.factory working with templates, here's how: unittest{ class A{} class B{int x;} A a=new B; auto

Re: object.factory with template classes for serializing subclasses automatically

2012-09-09 Thread Jacob Carlborg
On 2012-09-10 01:27, timotheecour wrote: Is there a way to use Object.factory with template classes? eg: class A(T){ T x; } auto a=Object.factory("A!int"); Right now this fails (returns null). Use case: If we had this, it would GREATLY simplify serialization (eg as in

object.factory with template classes for serializing subclasses automatically

2012-09-09 Thread timotheecour
Is there a way to use Object.factory with template classes? eg: class A(T){ T x; } auto a=Object.factory("A!int"); Right now this fails (returns null). Use case: If we had this, it would GREATLY simplify serialization (eg as in the orange library) by not having t

Re: Template classes

2009-04-16 Thread Jarrett Billingsley
On Thu, Apr 16, 2009 at 1:14 PM, Arild Boes wrote: > Actually the f-call syntactic sugar seems like a good way to keep core > classes of any library very lean and mean, whilst maintaining the ability to > expand the module without re-compiling the original library! (just import > this guy, and th

Re: Template classes

2009-04-16 Thread Arild Boes
Jarrett Billingsley skrev: On Wed, Apr 15, 2009 at 12:13 PM, Arild Boes wrote: Take a look at the 'this' of D2, it allows to create wrapper structs, so you can just add methods to the built-in arrays. Bye, bearophile Please elaborate on this. How does one do that? With the new, delicious "

Re: Template classes

2009-04-15 Thread bearophile
Jarrett Billingsley: > Though actually I'm not sure why bearophile suggested this, The original poster seems to want to add some methods to a standard array. With this you can give another module something that acts like an array that also has such methods, or replaces them. With the old way you

Re: Template classes

2009-04-15 Thread Jarrett Billingsley
On Wed, Apr 15, 2009 at 12:13 PM, Arild Boes wrote: >> Take a look at the 'this' of D2, it allows to create wrapper structs, so >> you can just add methods to the built-in arrays. >> >> Bye, >> bearophile > > Please elaborate on this. How does one do that? With the new, delicious "alias this."

Re: Template classes

2009-04-15 Thread Arild Boes
bearophile skrev: Andrew Spott: yes, however there are going to be a few new classes that will be implemented in this (dot products, cross products, etc) You mean a few new methods. Take a look at the 'this' of D2, it allows to create wrapper structs, so you can just add methods to the buil

Re: Template classes

2009-04-14 Thread bearophile
Andrew Spott: > yes, however there are going to be a few new classes that will be implemented > in this (dot products, cross products, etc) You mean a few new methods. Take a look at the 'this' of D2, it allows to create wrapper structs, so you can just add methods to the built-in arrays. Bye,

Re: Template classes

2009-04-14 Thread Andrew Spott
yes, however there are going to be a few new classes that will be implemented in this (dot products, cross products, etc) Thanks for the help. -Andrew Steven Schveighoffer Wrote: > On Tue, 14 Apr 2009 17:33:29 -0400, Steven Schveighoffer > wrote: > > > e.g., the following code does almost

Re: Template classes

2009-04-14 Thread Steven Schveighoffer
On Tue, 14 Apr 2009 17:33:29 -0400, Steven Schveighoffer wrote: e.g., the following code does almost the same thing you are doing without requiring a new class: correction, the code does *exactly* the same thing you are doing. -Steve

Re: Template classes

2009-04-14 Thread Steven Schveighoffer
On Tue, 14 Apr 2009 17:01:28 -0400, Andrew Spott wrote: So, the attached is supposed to be a class that creates a vector of any type (I would like it to only take numerical values (int, float, real, double, etc), however, I am ok with it taking others (not that I see why someone would us

Re: Template classes

2009-04-14 Thread Denis Koroskin
On Wed, 15 Apr 2009 01:01:28 +0400, Andrew Spott wrote: So, the attached is supposed to be a class that creates a vector of any type (I would like it to only take numerical values (int, float, real, double, etc), however, I am ok with it taking others (not that I see why someone would use

Template classes

2009-04-14 Thread Andrew Spott
So, the attached is supposed to be a class that creates a vector of any type (I would like it to only take numerical values (int, float, real, double, etc), however, I am ok with it taking others (not that I see why someone would use it that way). I tried to compile it with the following, but i