digitalmars.D.learn - [D1] type of type
- %u (6/6) Dec 23 2010 Is it possible to give a function a class(type) as an argument such that...
- %u (4/4) Dec 23 2010 Should have been this:
- Denis Koroskin (4/8) Dec 23 2010 Try this (not tested):
- %u (4/15) Dec 23 2010 Thanks,
- bearophile (4/5) Dec 24 2010 But this has strong limitations. For this problem templates are usually ...
- Steven Schveighoffer (6/10) Dec 27 2010 void func(T)(){
- %u (3/14) Dec 29 2010 The reason I asked for a non-templated solution is because they don't ha...
- Steven Schveighoffer (8/23) Dec 29 2010 I don't know what you mean. Templated solution does not require a commo...
- %u (8/32) Dec 29 2010 Yeah, sorry, I meant it the other way around: I need a common interface.
- %u (1/1) Dec 29 2010 Is it not possible to have a "type" type?
- Steven Schveighoffer (10/11) Dec 30 2010 In compile time, you can have type parameters with ease using templates.
Is it possible to give a function a class(type) as an argument such that the function can call its constructor, without using templates. void func(T t){ new T(); } Or, what is the type of a type? :)
Dec 23 2010
On Fri, 24 Dec 2010 01:28:49 +0300, %u <e ee.com> wrote:Should have been this: void func(type t){ new t(); }Try this (not tested): class Test {} Object o = Object.factory("Test");
Dec 23 2010
== Quote from Denis Koroskin (2korden gmail.com)'s articleOn Fri, 24 Dec 2010 01:28:49 +0300, %u <e ee.com> wrote:Thanks, Hiding in Object.. interesting :) Making the type a string, does this make using small class names more efficient?Should have been this: void func(type t){ new t(); }Try this (not tested): class Test {} Object o = Object.factory("Test");
Dec 23 2010
%u:Hiding in Object.. interesting :)But this has strong limitations. For this problem templates are usually used. Bye, bearophile
Dec 24 2010
On Thu, 23 Dec 2010 17:28:49 -0500, %u <e ee.com> wrote:Should have been this: void func(type t){ new t(); }void func(T)(){ new T(); } When you are passing types into functions, use templates. -Steve
Dec 27 2010
== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleOn Thu, 23 Dec 2010 17:28:49 -0500, %u <e ee.com> wrote:The reason I asked for a non-templated solution is because they don't have a common interface signature.Should have been this: void func(type t){ new t(); }void func(T)(){ new T(); } When you are passing types into functions, use templates. -Steve
Dec 29 2010
On Wed, 29 Dec 2010 10:33:21 -0500, %u <e ee.com> wrote:== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleI don't know what you mean. Templated solution does not require a common interface. This works with any type: void func(T)(){ T t; } Maybe you can post an example of what you are trying to solve? -SteveOn Thu, 23 Dec 2010 17:28:49 -0500, %u <e ee.com> wrote:The reason I asked for a non-templated solution is because they don't have a common interface signature.Should have been this: void func(type t){ new t(); }void func(T)(){ new T(); } When you are passing types into functions, use templates. -Steve
Dec 29 2010
== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleOn Wed, 29 Dec 2010 10:33:21 -0500, %u <e ee.com> wrote:Yeah, sorry, I meant it the other way around: I need a common interface. class C1: I .. class C9: I I'd like to pass any C(a) type to any C(b) object such that C(b) can spawn a C(a). What would be the common signature of these two functions? And how would the object save the type?== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleI don't know what you mean. Templated solution does not require a common interface. This works with any type: void func(T)(){ T t; } Maybe you can post an example of what you are trying to solve? -SteveOn Thu, 23 Dec 2010 17:28:49 -0500, %u <e ee.com> wrote:The reason I asked for a non-templated solution is because they don't have a common interface signature.Should have been this: void func(type t){ new t(); }void func(T)(){ new T(); } When you are passing types into functions, use templates. -Steve
Dec 29 2010
On Wed, 29 Dec 2010 19:25:05 -0500, %u <e ee.com> wrote:Is it not possible to have a "type" type?In compile time, you can have type parameters with ease using templates. During runtime, you can use the TypeInfo object, which is accessed via typeid: auto ti = typeid(int); // ti is TypeInfo type See docs for TypeInfo in object.di Now, the only issue with TypeInfo is that D runtime reflection is woefully supported. You can't do much with a TypeInfo. So again, what is it you want to do with the type type? -Steve
Dec 30 2010