inner templates?

Daniel Keep daniel.keep.lists at gmail.com
Thu May 24 22:32:04 PDT 2007



dennis luehring wrote:
> template fe(double p=1e-14)
> {
>   template fe_help(double p, double s=1, double f=1, int n=1)
>   {
>     if( s > p )
>       const fe_help = fe_help!(p, s/n,f+s/n,n+1);
>     else
>       const fe_help = f;
>   }
>   return fe_help!(p);
> }
> 
> proposal: we've got inner functions, inner classes - what speaks against
> inner templates? (except that the d compiler don't know the last one)

We already do.  Just change that second-last line to:

  const fe = fe_help!(p);

The problem is that then you have to use it like so:

  fe!().fe;

Since having more than one member in a template breaks the implicit
property trick.  Of course, you can get around that by doing this:

private template fe_help(double p, double s=1, double f=1, int n=1)
{
    if( s > p )
        const fe_help = fe_help!(p, s/n,f+s/n,n+1);
    else
        const fe_help = f;
}

template fe(double p=1e-14)
{
    const fe = fe_help!(p);
}

The "private" will hide the fe_help template from outsiders.  If you
don't care about that middle blank line, it's even the same number of
lines of code!

See, what you should be asking for is that private members of a template
don't break the implicit property trick thing (no idea what it's
"officially" called).

But that said, it's a pretty minor problem, and easy to work around.

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list