www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static switch

reply "cal" <callumenator gmail.com> writes:
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
Jun 11 2012
next sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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
Jun 12 2012
parent "cal" <callumenator gmail.com> writes:
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!
Jun 12 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
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
Jun 12 2012