Identifier (...) is too long by X characters
Sean Kelly
sean at f4.ca
Mon Jul 10 08:45:03 PDT 2006
Tom S wrote:
> Don Clugston wrote:
>> If Tuple!() works with a nesting level of 50, the limit would have to
>> be pretty big.
>
> Yeah, and it would cause DMD to eat RAMs like a medium-sized dragon.
>
>
>> Maybe in the future, we'll be able to add some kind of 'final'
>> declaration to templates, which would indicate that they don't need to
>> be stored in the object file or library, and can be discarded from the
>> symbol table as soon as they are instantiated. This would be
>> particularly useful for recursive templates, which can easily spew
>> reams of garbage into the object file.
>
> My thoughts exactly :) Right now I'd be happy with anything that worked
> though...
>
>
> And while we're at recursive templates, don't you think that the
> limitation for recursive templates, which causes the error 'template
> instance recursive template expansion for template argument X' is pretty
> arbitary ? It can be hacked around, after all:
>
>
> // tmp.d
> import std.stdio;
>
>
> struct Foo(T/*, int dummy=0*/) {
> Foo!(Foo!(T/*, dummy+1*/)) rec()() { // line 5
> Foo!(Foo!(T/*, dummy+1*/)) res;
> return res;
> }
> }
>
>
> void main() {
> Foo!(int) a;
> writefln(typeid(typeof(a)));
> auto b = a.rec!()();
> writefln(typeid(typeof(b)));
> }
> // ----
>
> tmp.d(5): template instance recursive template expansion for template
> argument Foo
>
> But when you uncomment the 'dummies', it compiles and runs without any
> problems...
>
> Yeah, I know, the error is an artifact of how the instantiation works,
> that it's not 'lazy' like in C++. But since it can be fooled into
> working, couldn't DMD apply the hack automagically ?
I don't know. To do so would be like allowing:
struct S
{
S val;
}
I'm not sure I'd want the compiler to try and "fix" a mistake I'd made
involving this. Adding an integer is pretty easy anyway.
Sean
More information about the Digitalmars-d-bugs
mailing list