SimpleCxxLib
packageclass Set<ValueType>
Constructor | |
Creates an empty set of the specified element type. | |
Methods | |
Adds an element to this set, if it was not already there. | |
Removes all elements from this set. | |
Returns true if the specified value is in this set. | |
Returns the first value in the set in the order established by the for iterator. | |
Returns true if this set contains no elements. | |
Implements the subset relation for sets. | |
Iterates through the elements of the set and calls fn(value) for each one. | |
Removes an element from this set. | |
Returns the number of elements in this set. | |
Converts the set to a printable string representation. | |
Operators | |
Returns true if set1 and set2 are different. | |
Returns the intersection of sets set1 and set2 , which is the set of all elements that appear in both. | |
Removes any elements from set1 that are not present in set2 . | |
Returns the union of sets set1 and set2 , which is the set of elements that appear in at least one of the two sets. | |
Adds all of the elements from set2 (or the single specified value) to set1 . | |
Returns the difference of sets set1 and set2 , which is all the elements that appear in set1 but not set2 . | |
Removes the elements from set2 (or the single specified value) from set1 . | |
Returns true if set1 and set2 contain the same elements. |
Set();
Usage:
Set<ValueType> set; Set<ValueType> set = { value1, value2, value3 };
int size() const;
Usage:
count = set.size();
bool isEmpty() const;
true
if this set contains no elements.
Usage:
if (set.isEmpty()) ...
void add(const ValueType & value); void insert(const ValueType & value);
set
class, this method
is also exported as insert
.
Usage:
set.add(value);
void remove(const ValueType & value);
Usage:
set.remove(value);
bool contains(const ValueType & value) const;
true
if the specified value is in this set.
Usage:
if (set.contains(value)) ...
bool isSubsetOf(const Set & set2) const;
true
if every element of this set is
contained in set2
.
Usage:
if (set.isSubsetOf(set2)) ...
void clear();
Usage:
set.clear();
ValueType first() const;
first
generates an error.
Usage:
ValueType value = set.first();
string toString();
Usage:
string str = set.toString();
void mapAll(void (*fn)(ValueType)) const; void mapAll(void (*fn)(const ValueType &)) const; void mapAll(FunctorType fn) const;
fn(value)
for each one. The values are processed in ascending order, as defined
by the comparison function.
Usage:
set.mapAll(fn);
bool operator==(const Set & set2) const;
true
if set1
and set2
contain the same elements.
Usage:
set1 == set2
bool operator!=(const Set & set2) const;
true
if set1
and set2
are different.
Usage:
set1 != set2
Set operator+(const Set & set2) const; Set operator+(const ValueType & element) const;
set1
and set2
, which
is the set of elements that appear in at least one of the two sets. The
right hand set can be replaced by an element of the value type, in which
case the operator returns a new set formed by adding that element.
Usage:
set1 + set2 set1 + element
Set operator*(const Set & set2) const;
set1
and set2
,
which is the set of all elements that appear in both.
Usage:
set1 * set2
Set operator-(const Set & set2) const; Set operator-(const ValueType & element) const;
set1
and set2
,
which is all the elements that appear in set1
but
not set2
. The right hand set can be replaced by an
element of the value type, in which case the operator returns a new
set formed by removing that element.
Usage:
set1 - set2 set1 - element
Set & operator+=(const Set & set2); Set & operator+=(const ValueType & value);
set2
(or the single
specified value) to set1
. As a convenience, the
Set
package also overloads the comma operator so
that it is possible to initialize a set like this:
Setdigits; digits += 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
Usage:
set1 += set2; set1 += value;
Set & operator*=(const Set & set2);
set1
that are not present in
set2
.
Usage:
set1 *= set2;
Set & operator-=(const Set & set2); Set & operator-=(const ValueType & value);
set2
(or the single
specified value) from set1
. As a convenience, the
Set
package also overloads the comma operator so
that it is possible to remove multiple elements from a set
like this:
digits -= 0, 2, 4, 6, 8;which removes the values 0, 2, 4, 6, and 8 from the set
digits
.
Usage:
set1 -= set2; set1 -= value;