const argument

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Mar 28 04:21:52 PDT 2009


On Sat, Mar 28, 2009 at 6:12 AM, TSalm <TSalm at free.fr> wrote:
> Hello,
>
> Is there a way to specifie a constant argument ( I would say an argument for
> which his value is evaluate at compile time )
>
> For example, something like this :
>
> /* -------- CODE --------- */
> import tango.io.Stdout;
>
> void func(const bool constArg)
> {
>    static if (constArg)
>        Stdout("Yes").newline;
>    else
>        Stdout("No").newline;
> }
>
> void main()
> {
>    func( true );
>    func( false );
> }
> /* -------- END CODE --------- */

You have to do it with templates:

void func(bool constArg)()
{
    static if(constArg) ... else ...
}

func!(true)();
func!(false)();

Walter suggested, in the D2 presentation at the conference in 2007,
that there should be "static" parameters which would work the way your
code should work.


More information about the Digitalmars-d-learn mailing list