www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Making TypeInfo.next() return a const(TypeInfo) was a bad idea

reply Benjamin Thaut <code benjamin-thaut.de> writes:
Because you are now no longer able to do stuff like this:

void log(...)
{
   auto t = _arguments[0];
   while(some condition)
   {
     t = t.next();
   }
}

To be actually able to use TypeInfo.next you will now need the ConstRef 
(hack) from phobos. Afaik there is no such thing in druntime which makes 
working with TypeInfo.next within druntime a real pita.

Any suggestions?

Kind Regards
Benjamin Thaut
Oct 14 2012
next sibling parent reply =?ISO-8859-15?Q?Alex_R=F8nne_Petersen?= <alex lycus.org> writes:
On 14-10-2012 12:19, Benjamin Thaut wrote:
 Because you are now no longer able to do stuff like this:

 void log(...)
 {
    auto t = _arguments[0];
    while(some condition)
    {
      t = t.next();
    }
 }

 To be actually able to use TypeInfo.next you will now need the ConstRef
 (hack) from phobos. Afaik there is no such thing in druntime which makes
 working with TypeInfo.next within druntime a real pita.

 Any suggestions?

 Kind Regards
 Benjamin Thaut
None, to be honest. I can only recommend going with a cast hack or something similar for now. But this is a problem we *must* solve. It is something I also ran into often while hacking on druntime. -- Alex Rønne Petersen alex lycus.org http://lycus.org
Oct 14 2012
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, October 15, 2012 02:20:23 Alex R=C3=B8nne Petersen wrote:
 But this is a problem we *must* solve. It is something I also ran int=
o
 often while hacking on druntime.
If we really need Rebindable in druntime, then we can simply move it to= an=20 appropriate place in druntime and alias std.typecons.Rebindable to it. core.time exists specifically because druntime needed some of the datet= ime stuff=20 (most particularly the duration stuff). Otherwise, everything in it wou= ld be in=20 std.datetime (where it was when originally proposed). We can do the same with other constructs if we really need to. We just = don't=20 want to be moving them to druntime if we don't actually need to. - Jonathan M Davis
Oct 14 2012
prev sibling parent reply "Mehrdad" <wfunction hotmail.com> writes:
http://stackoverflow.com/questions/12506338
Oct 14 2012
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, October 15, 2012 08:44:51 Mehrdad wrote:
 http://stackoverflow.com/questions/12506338
Yes. The problem is that he's trying to do something in druntime, and Rebindable is declared in Phobos. - Jonathan M Davis
Oct 14 2012
prev sibling parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 10/14/2012 12:19 PM, Benjamin Thaut wrote:
 Because you are now no longer able to do stuff like this:

 void log(...)
 {
    auto t = _arguments[0];
    while(some condition)
    {
      t = t.next();
    }
 }

 To be actually able to use TypeInfo.next you will now need the ConstRef
 (hack) from phobos. Afaik there is no such thing in druntime which makes
 working with TypeInfo.next within druntime a real pita.
That's the general problem of non-rebindable const references which is a real pita. There has been a pull request to implement it (https://github.com/D-Programming-Language/dmd/pull/3) but unfortunately it never made it into the compiler.
 Any suggestions?
You could create a recursive function hoping for tail-recursion-optimization and inlining: void log(...) { static const(TypeInfo) drillInto(const(TypeInfo) t) { if(some condition) return drillInto(t.next()); return t; } auto t = drillInto(_arguments[0]); }
Oct 14 2012