Thread overview
static switch
Jun 12, 2012
cal
Jun 12, 2012
Dmitry Olshansky
Jun 12, 2012
cal
Jun 12, 2012
bearophile
June 12, 2012
Does a switch statement acting on a template parameter act just like a chain of  static if-else's? That is, does it just generate the code for the matching case?

enum E { A, B, C }

class Blah(E param) {
  void foo() {
    switch(param) {
      case(E.A) : blah;
      case(E.B) : ....
      default:
    }
  }
}

Thanks,
cal
June 12, 2012
On 12.06.2012 10:13, cal wrote:
> Does a switch statement acting on a template parameter act just like a
> chain of static if-else's? That is, does it just generate the code for
> the matching case?
>
> enum E { A, B, C }
>
> class Blah(E param) {
> void foo() {
> switch(param) {
> case(E.A) : blah;
> case(E.B) : ....
> default:
> }
> }
> }
>

It doesn't. It's easy to check anyway.

-- 
Dmitry Olshansky
June 12, 2012
cal:

> Does a switch statement acting on a template parameter act just like a chain of  static if-else's? That is, does it just generate the code for the matching case?

See:
http://d.puremagic.com/issues/show_bug.cgi?id=6921

Bye,
bearophile
June 12, 2012
On Tuesday, 12 June 2012 at 08:35:44 UTC, Dmitry Olshansky wrote:
> It doesn't. It's easy to check anyway.

Not for me :) I just saw that it worked, and wondered if it worked statically.
Thanks!