static if syntax

Steve Teale steve.teale at britseyeview.com
Thu Jun 4 23:06:40 PDT 2009


Daniel Keep Wrote:

> 
> 
> Steve Teale wrote:
> > If I write:
> > 
> > static if (cond1)
> > {
> >  ...
> > }
> > else static if (cond2)
> > {
> >  ...
> > }
> > else
> > {
> >  ...
> > }
> > 
> > is the block after the final else 'static'? Would it be better if the 'static' before the whole sequence of tests applied throughout rather than having to be explicitly restated in some places, but not in others?
> > 
> > Steve
> 
> I don't think so.  The problem is that there's no such thing as "chained
> ifs" in the language.  What you're actually looking at is this:
> 
> static if (cond1)
> {
>  ...
> }
> else
> {
>  static if (cond2)
>  {
>   ...
>  }
>  else
>  {
>   ...
>  }
> }
> 
> Once you realise that there's nothing special about either "else if" or
> "else static if", it makes perfect sense.

Daniel,

So I have to write

static if (cond1)
{
}
else static if (cond2)
{
}
else static if (true)
{
   // for the default alternative?
}

Looks a bit strange
Steve



More information about the Digitalmars-d mailing list