Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
October 25, 2012 TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Hi! Tell me please,are any TypeInfo/typeid/classinfo manipulations possible? For example I need a struct that overload typeid, or something like that? Some time ago I tried to write some smart pointer that overlad classinfo property in accordance with the real type of hold object,but I failed to do this becouse of not having possibility to declar static and non-static version of the one function.Maybe there are better ways to do this? |
October 26, 2012 Re: TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
> Hi!
> Tell me please,are any TypeInfo/typeid/classinfo manipulations possible?
> For example I need a struct that overload typeid, or something like that?
>
> Some time ago I tried to write some smart pointer that overlad classinfo property in accordance with the real type of hold object,but I failed to do this becouse of
> not having possibility to declar static and non-static version of the one function.Maybe there are better ways to do this?
Or maybe there are a possibility to parametrize class by TypeInfo?
|
October 27, 2012 Re: TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | On Friday, 26 October 2012 at 19:57:14 UTC, Zhenya wrote:
> On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
>> Hi!
>> Tell me please,are any TypeInfo/typeid/classinfo manipulations possible?
>> For example I need a struct that overload typeid, or something like that?
>>
>> Some time ago I tried to write some smart pointer that overlad classinfo property in accordance with the real type of hold object,but I failed to do this becouse of
>> not having possibility to declar static and non-static version of the one function.Maybe there are better ways to do this?
>
> Or maybe there are a possibility to parametrize class by TypeInfo?
Is my question is so meaningless, that no one even say why? :(
|
October 27, 2012 Re: TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote: > Hi! > Tell me please,are any TypeInfo/typeid/classinfo manipulations possible? > For example I need a struct that overload typeid, or something like that? It is impossible to overload typeid typeinfo. > Some time ago I tried to write some smart pointer that overlad classinfo property in accordance with the real type of hold object,but I failed to do this becouse of > not having possibility to declar static and non-static version of the one function.Maybe there are better ways to do this? I can barely understand what exactly you were doing. If you post some code example it will probably help to find solution. |
October 27, 2012 Re: TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | On Friday, 26 October 2012 at 19:57:14 UTC, Zhenya wrote:
> On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
>> Hi!
>> Tell me please,are any TypeInfo/typeid/classinfo manipulations possible?
>> For example I need a struct that overload typeid, or something like that?
>>
>> Some time ago I tried to write some smart pointer that overlad classinfo property in accordance with the real type of hold object,but I failed to do this becouse of
>> not having possibility to declar static and non-static version of the one function.Maybe there are better ways to do this?
>
> Or maybe there are a possibility to parametrize class by TypeInfo?
What do you mean: "to parametrize class by Typeinfo"?
class A { }
A!TypeInfo var;
If you mean this, than how it can help?
|
October 27, 2012 Re: TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | > What do you mean: "to parametrize class by Typeinfo"?
>
> class A { }
> A!TypeInfo var;
>
> If you mean this, than how it can help?
It would be well if I could create object that inherits class with this typeinfo.
|
October 27, 2012 Re: TypeInfo manipulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | I have double dispatcher: template Dispatcher(R) { R execute(Left,Right)(R delegate(Left,Right) f,Object left,Object right) { return f(cast(Left)left,cast(Right)right); } struct Dispatcher { private R delegate(Object,Object)[Tuple!(TypeInfo_Class,TypeInfo_Class)] m_callbacks; void add(Left,Right)(R delegate(Left,Right) f) { m_callbacks[tuple(Left.classinfo,Right.classinfo)] = (Object l,Object r){return execute!(Left,Right)(f,l,r);}; } void remove(Left,Right)() { m_callbacks.remove(tuple(Left.classinfo,Right.classinfo)); } R opCall(Object l,Object r) { R delegate(Object,Object)* callback = tuple(l.classinfo,r.classinfo) in m_callbacks; return (*callback)(l,r); } } } And I have some class ierarhy: class GameObject { } class Foo : GameObject { } class Bar : GameObject { } problem is to create some wrapper to this classes struct GameHandle(Type) and this code work void main() { Dispatcher!void d; d.add!(GameHandle!Foo,GameHandle!Bar)((GameHandle!Foo,GameHandle!Bar){writeln("haha");}); GameHandle!GameObject a;a.m_hold = new Foo; GameHandle!GameObject b;b.m_hold = new Bar; d(a,c); readln(); } |
Copyright © 1999-2021 by the D Language Foundation