inner templates?
dennis luehring
dl.soluz at gmx.net
Thu May 24 23:08:38 PDT 2007
Daniel Keep schrieb:
>
> 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).
did you think an inner template (or a changed implicit property thing)
would made D more clean?
> But that said, it's a pretty minor problem, and easy to work around.
your right - but it should be no need for such workaround - maybe in
later D versions
thx
>
> -- Daniel
>
More information about the Digitalmars-d
mailing list