John Levon <[EMAIL PROTECTED]> writes:

| Help !
>
| template <typename T> class enum_set {
| public:
|         typedef int value_type;
|  
|         enum_set() : val_(0) {}
|         enum_set(T t) : val_(t) {}
|  
|         bool operator==(enum_set<T> const & s) const {
|                 return val_ == s.val_;
|         }

should not be class function
(and you cheat again by introducing a int... why should that type
really make an apperance?)
  
|         bool operator!=(enum_set<T> const & s) const {
|                 return !(s == *this);
|         }

should not be class function
(better than last time.)
  
|         enum_set operator|(enum_set<T> const & s) const {
|                 return enum_set<T>(val_ | s.val_);
|         }

should not be class function
  
|         enum_set operator&(enum_set<T> const & s) const {
|                 return enum_set<T>(val_ & s.val_);
|         }

should not be class function
  
|         enum_set & operator=(enum_set<T> const & s) {
|                 val_ = s.val_; return *this;
|         }

ok as class function.
  
|         void operator|=(enum_set<T> const & s) {
|                 (*this) = (*this) | s;
|         }

should not be class function.
  
|         void operator&=(enum_set<T> const & s) {
|                 (*this) = (*this) & s;
|         }

should not be class function

| private:
|         // used by operators above
|         enum_set(value_type v) : val_(v) { }

No, do not do this, use static_cast in the functions that need it
instead. (btw. are you sure it is used at all? T is not value_type)
  
|         value_type val_;
| };
>
| HTF do I get :
>
|       if (blah & key_modifier::ctrl)
>
| to work ??

What type is blag?
and since LHS is not of type enum_set<> you operator
enum_set<>::operator& does not come into play.

|       operator bool() conversion just gives ambiguous overloads

Don't do that then...

As said I do not like this kind of template classes a lot, in cases
like this it is, IMHO, a lot better to use concrete classes.


| Please diss the above where necessary as well please.

more?

-- 
        Lgb


Reply via email to