On 04/03/2012 02:00 PM, Nick Sabalausky wrote:
"Timon Gehr"<timon.g...@gmx.ch> wrote in message
news:jlej27$mvi$1...@digitalmars.com...
This is the right way to work around this issue. It works now and does not
imply any kind of overhead at runtime:
void foo(){
void a()(){ ... }
void b() { ... }
}
That's a very simple workaround (albiet unintuitive - unless I'm just too
tired right now). It leads me to two questions:
1. How the heck does that work?
Symbol lookup is done upon the first instantiation of the local template.
2. What, if any, problems would arise from just automatically doing that
behind-the-scenes? Ie, to just automatically turn all non-templated nested
functions into no-parameter templated nested functions? Would that be a
feasable solution?
Your proposal is basically to allow a local function to forward
reference any symbol that is declared before the local function is first
referenced.
This still has the following problem:
void a(){/*cannot reference c*/}
void b(){/*because this references a*/}
void c(){/*references a and b*/ }
It would work by reordering the code like so:
void b(){/*references a*/}
void a(){/*references c*/}
void c(){/*references a and c*/}
That would be extremely unintuitive.