inner templates?
Kirk McDonald
kirklin.mcdonald at gmail.com
Thu May 24 15:05:35 PDT 2007
dennis luehring wrote:
> hi
>
> i've try to write an template wich calculates e
>
> ok here it is - but wait i need a helper template to reduce the
> interface to my needs (just to adjust the precision) - is there any way
> getting rid of these helper template (maybe an inner-template or
> something)?
>
> --
> import std.stdio;
>
> template e_help(double p, double s, double f, int n)
> {
> static if( s > p )
> const e_help = e_help!(p, s/n,f+s/n,n+1);
> else
> const e_help = f;
> }
>
> // this is the interface i want - but without the e_help template
> template e(double p = 1e-14)
> {
> const e = e_help!(p, 1, 1, 1);
> }
>
> void main()
> {
> writefln("e: ", e!());
> }
> --
>
> ciao dennis
Default arguments should do it in this case:
template e(double p=1e-14, double s=1, double f=1, int n=1)
{
static if( s > p )
const e = e!(p, s/n, f+s/n, n+1);
else
const e = f;
}
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list