Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 05:25:06PM +, cc via Digitalmars-d-learn wrote: > On Tuesday, 3 May 2022 at 17:05:09 UTC, H. S. Teoh wrote: > > Oops, sorry, I made a mistake. The definition of Serializable should be: > > > > class Serializable(Base, Derived = Object) : Base {} > > There we go, wo

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 17:05:09 UTC, H. S. Teoh wrote: Oops, sorry, I made a mistake. The definition of Serializable should be: class Serializable(Base, Derived = Object) : Base {} There we go, works with this, now I get what it's trying to do: ```d class Serializable(Base, Derived

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 04:59:42PM +, cc via Digitalmars-d-learn wrote: > On Tuesday, 3 May 2022 at 16:51:33 UTC, H. S. Teoh wrote: [...] > > > On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: > > > > class Base : Serializable!(Base) { ... } > > > > class Derived : Seri

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 16:51:33 UTC, H. S. Teoh wrote: On Tue, May 03, 2022 at 04:38:23PM +, cc via Digitalmars-d-learn wrote: On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: >class Base : Serializable!(Base) { ... } >class Derived : Serializable!(Base, Derived) { ... }

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 16:38:23 UTC, cc wrote: This is really interesting syntax, I'm surprised that works! Can read a little more on my blog about it: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_06_10.html#tip-of-the-week pretty cool little pattern.

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 04:38:23PM +, cc via Digitalmars-d-learn wrote: > On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: > > class Base : Serializable!(Base) { ... } > > class Derived : Serializable!(Base, Derived) { ... } > > This is really interesting syntax, I'm surprised

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote: class Base : Serializable!(Base) { ... } class Derived : Serializable!(Base, Derived) { ... } This is really interesting syntax, I'm surprised that works!

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Arafel via Digitalmars-d-learn
On 3/5/22 16:48, Adam D Ruppe wrote: Believe it or not, you don't need to touch the compiler. Open your druntime's object.d and search for `RTInfo` http://druntime.dpldocs.info/object.RTInfo.html That is instantiated for every user defined type in the program and you have the compile time inf

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 03, 2022 at 04:38:53PM +0200, Arafel via Digitalmars-d-learn wrote: > On 3/5/22 15:57, Adam D Ruppe wrote: > > So doing things yourself gives you some control. > > Yes, it is indeed possible (I acknowledged it), but I think it's much > more cumbersome than it should, and puts the load

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 14:38:53 UTC, Arafel wrote: Actually, it would be cool to do it through an interface, although I don't think an interface's static constructors are invoked by the implementing classes... it would be cool, though. yeah interfaces can't have constructors. I'd try it my

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Arafel via Digitalmars-d-learn
On 3/5/22 15:57, Adam D Ruppe wrote: So doing things yourself gives you some control. Yes, it is indeed possible (I acknowledged it), but I think it's much more cumbersome than it should, and puts the load on the user. If templated this worked in static context (ideally everywhere else too)

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 13:25:14 UTC, Arafel wrote: I'd like to do a runtime registration system myself, using a "template this" static constructor. A simple version supporting only default constructors would be: Yeah, you can't template this a static constructor, but you can just use a sta

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Arafel via Digitalmars-d-learn
On 3/5/22 14:46, Adam D Ruppe wrote: Put a static constructor in the class which appends a factory delegate to an array or something you can use later. Then you can use your own thing to construct registered objects. I'd like to do a runtime registration system myself, using a "template this"

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 10:48:53 UTC, bauss wrote: Object.factory calls TypeInfo_Class.find which just loops through ModuleInfo and then looks if any of the entries in localClasses has a name that matches. Afterwards it calls the create function on the TypeInfo_Class which of course isn't "

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote: something I can pass to `Object.factory`. Object.factory is useless and will hopefully be removed someday. Instead, make your own factory registration function. Put a static constructor in the class which appends a factory delegate to an arra

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Arafel via Digitalmars-d-learn
On 3/5/22 12:48, bauss wrote: This is where compile-time has its limits compared to runtime type creation, because templates only live during compile-time then it isn't really that easy to do something like this, where it would be trivial in other languages like C#. That's something I don't r

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread bauss via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 09:52:56 UTC, cc wrote: On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote: Given a runtime typeid, how can I get the equivalent fullyQualifiedName without attempting to mangle the string myself manually? e.g. something I can pass to `Object.factory`. Actually, looki

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote: Given a runtime typeid, how can I get the equivalent fullyQualifiedName without attempting to mangle the string myself manually? e.g. something I can pass to `Object.factory`. Actually, looking at this further, does Object.factory even suppor

How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread cc via Digitalmars-d-learn
This produces compatible strings between symbol and runtime type: ```d class Foo {} void main() { alias Foo F; writeln(fullyQualifiedName!F); auto f = new F; writeln(typeid(f).name); } ``` ``` test.Foo test.Foo ``` But if the class is a template, the strings differ