www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - RFC: A tailconst template

reply =?ISO-8859-15?Q?S=F6nke_Ludwig?= writes:
Since tailconst support for class types is still missing, I decided to try and
clean up the many related workarounds in my code. The result after a few hours
of trying to get the templates/ctfe-functions do what I want is a template
which casts the const/invariant class reference to void* internally and defines
proxy methods for all methods of the original class. This is already pretty
transparent in usage. But there are some issues left:


1. __traits(allMembers, T) does not seem to list methods which have only const
    or invariant overloads:

    class C {
      const int myfunc();
    }

    in this case __traits(allMembers, C) would be empty. If there is no specific
    reason for this, I'll file a bug report for this.

2. Support for public member variables is missing

   Currently, only methods are supported. Personally, I'm using public variables
   in classes pretty seldom. So this will come later.

3. Enums are reported as "int" by stringof

   Is there some other way to get the type identifier as a string at compile
   time? typeid(T).toString() works fine at runtime - but that doesn't help
   for compile-time code generation.
   (this would be http://d.puremagic.com/issues/show_bug.cgi?id=1610)


PS: ignore the copyright notice in the attached code - this is public domain
Feb 23 2008
parent =?ISO-8859-15?Q?S=F6nke_Ludwig?= writes:
Sönke Ludwig wrote:
 
 1. __traits(allMembers, T) does not seem to list methods which have only 
 const
    or invariant overloads:
 
    class C {
      const int myfunc();
    }
 
    in this case __traits(allMembers, C) would be empty. If there is no 
 specific
    reason for this, I'll file a bug report for this.
 
related bug report: http://d.puremagic.com/issues/show_bug.cgi?id=1874
Feb 27 2008