On Mon, Sep 15, 2003 at 02:47:40PM +0000, Angus Leeming wrote: > Andre Poenitz wrote: > > > On Mon, Sep 15, 2003 at 02:22:57PM +0000, Angus Leeming wrote: > > > > +struct Class { \ > > + /** The default argument is nasty, \ > > + * but allows us to use Class in STL containers. \ > > + */ \ > > + Class(Enum val = static_cast<Enum>(-1)) : val_(val) {} \ > > + operator Enum() const{ return val_; } \ > > +private: \ > > + Enum val_; \ > > +} > > > > If you don't like the default argument, why don't you use two > > constructors? > > > > + Class() : val_(-1) {} \ > > + Class(Enum val) : val_(val) {} \ > > Entirely reasonable. But also exactly equivalent. Or do I miss something?
Well... the compiler does not need to push an argument to the stack in the default case and the cast is gone... So --- not _much_ difference. > > > I am not too fond of this macro business and I'd rather resort to a > > separate LColor_enum.h header that contains this some 'ColorEnum' enum > > only and include this header when it is needed. This would serve almost > > the same purpose, wouldn't it? > > Alternatively, I could add this to LColor.h: > > class LColorEnum { > // The default argument is nasty, > // but allows us to use LColorEnum in STL containers. > LColorEnum(LColor::color val = static_cast<LColor::color>(-1)) > : val_(val) {} > operator LColor::color() const{ return val_; } > private: > LColor::color val_; > }; Why to LColor.h and not to a separate header LColor_enum.h containing enum ColorEnum { /// No particular color---clear or default none, /// The different text colors black, /// white, ... }; [In a namespace or not, or named 'color_none' or not, or...] > Personally, I'm ambivalent. It seems to me that use of the macro to > do this is safe and would save some lines of code if we were to use > the same technique elsewhere. However, I do understand that macros are > evil. > > How do you feel about this? As I said, I'd prefer a de-coupled version without macros, but as I am already a bit upset about people going into nitpick mode the final words are: I do not really care. Do whatever you want here, but do it quick, and go back to solve serious problems afterwards. Andre'