[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:

| I am not sure how safe those template operators are.

This is the last version, I am a bit unsure about the odr implications
of the friends in EnumSet.

template <class E>
class EnumSet {
public:
        EnumSet() : e_(E(0)) {}
        EnumSet(E val) : e_(val) {};
        EnumSet & set(E v) { e_ |= v; return *this; }
        EnumSet & reset() { e_ = E(0); return *this; }
        EnumSet & reset(E v) { e_ &= ~v; return *this; }
        bool test(E v) const { return e_ & v; }
        bool any() const { return e_ != 0; }
        bool none() const { return e_ == 0; }
        E val() const { return e_; }
        friend
        E operator~(E e) { return static_cast<E>(~static_cast<int>(e)); }
        friend
        void operator|=(E & e1, E e2) { e1 = static_cast<E>(e1 | e2); }
        friend
        void operator&=(E & e1, E e2) { e1 = static_cast<E>(e1 & e2); }
private:
        E e_;
};

-- 
        Lgb

Reply via email to