Google

C++ Portable Types Library (PTypes) Version 1.7


Top: Basic types: cset: Operators

#include <ptypes.h>

// assignment
cset& cset::operator= (const cset& s);

// union
cset& cset::operator+= (const cset& s);
cset& cset::operator+= (char b);
cset  cset::operator+  (const cset& s) const;
cset  cset::operator+  (char b) const;
friend cset operator+  (char b, const cset& s);

// difference
cset& cset::operator-= (const cset& s);
cset& cset::operator-= (char b);
cset  cset::operator-  (const cset& s) const;
cset  cset::operator-  (char b) const;

// intersection
cset& cset::operator*= (const cset& s);
cset  cset::operator*  (const cset& s) const;

// comparison
bool  cset::operator== (const cset& s) const;
bool  cset::operator!= (const cset& s) const;
bool  cset::operator<= (const cset& s) const;
bool  cset::operator>= (const cset& s) const;

// membership
friend bool operator& (char b, const cset& s);

The following rules apply to +, –, and *:

  • An ordinal O is in X + Y if and only if O is in X or Y (or both). Equivalent of bitwise OR.

  • O is in X – Y if and only if O is in X but not in Y. Equivalent of bitwise AND NOT.

  • O is in X * Y if and only if O is in both X and Y. Equivalent of bitwise AND.

The following rules apply to comparison operations <=, >=, ==, !=:

  • X <= Y is true just in case every member of X is a member of Y; Z >= W is equivalent to W <= Z.

  • U == V is true just in case U and V contain exactly the same members; otherwise, U != V is true.

For an ordinal O and a set S, O & S is true just in case O is a member of S. Unlike Pascal, where membership operator is in, PTypes uses ampersand "&" as a membership test operator.

Note: regardless of whether default char is signed or unsigned (usually set through compiler options) cset always treats char arguments as unsigned. This means, if the value of an argument is -1, e.g. in call to operator & or operator +, the value will be converted to 255, -2 will be treated as 254, etc.

See also: Constructors, Manipulation


PTypes home