H
Hicham Mouline
Imagine we have an abstract base class ABC and derived classes D1, D2, ...
Dn
I am being told a code pattern to "enforce" all cases are handled is such:
enum ABCTypes { D1Tag, D2Tag, .... DnTag };
const ABC& base
ABCTypes t = base.getTag();
swich(t)
{
case D1Tag:
...
case DnTag:
}
without the default branch.
If you add a Dnplus1 derived class and its tag Dnplus1Tag in the enum
ABCTypes ,
all code patterns with the switch-case will generate an error if you forget
to handle the Dnplus1 case.
1) Does the standard "require" handling all cases of the enum? Or does it
only say a conforming implementation should print a warning?
2) Are there opinions on this style? I don't like the use of the getTag()
method in the ABC class to facilitate this style.
3) Is there a way to use boost::mpl and/or boost:reprocessor to generate
the switch-case statement?
rds,
Dn
I am being told a code pattern to "enforce" all cases are handled is such:
enum ABCTypes { D1Tag, D2Tag, .... DnTag };
const ABC& base
ABCTypes t = base.getTag();
swich(t)
{
case D1Tag:
...
case DnTag:
}
without the default branch.
If you add a Dnplus1 derived class and its tag Dnplus1Tag in the enum
ABCTypes ,
all code patterns with the switch-case will generate an error if you forget
to handle the Dnplus1 case.
1) Does the standard "require" handling all cases of the enum? Or does it
only say a conforming implementation should print a warning?
2) Are there opinions on this style? I don't like the use of the getTag()
method in the ABC class to facilitate this style.
3) Is there a way to use boost::mpl and/or boost:reprocessor to generate
the switch-case statement?
rds,