Navigation: Up, Table of Contents, Bibliography, Index, Title Page

set (set)

Definition

An object of the class set<Key, Compare> stores unique elements of type Key. It allows for the retrieval for the elements themselves. The elements in the set are ordered by the ordering relation Compare.

#include <set.h>

Types

set<Key, Compare>::iterator
A const bidirectional iterator.

Creation

set<Key, Compare> S ( Compare comp = Compare());
Introduces an empty set.

set<Key, Compare> S ( set<Key, Compare> S1);
Copy constructor.

Operations

set<Key, Compare> & S = set<Key, Compare> S1 Assignment.
bool S == set<Key, Compare> S1
Equality test: Two sets are equal, if the sequences S and S1 are elementwise equal.
bool S < set<Key, Compare> S1 Returns true if S is lexicographically less than S1, false otherwise.
set<Key, Compare>::iterator
S.begin () Returns a constant iterator referring to the first element in set S.
set<Key, Compare>::iterator
S.end () Returns a constant past-the-end iterator of set S.
bool S.empty () Returns true if S is empty.
int S.size () Returns the number of items in set S.

Insert and Erase

set<Key, Compare>::iterator
S.insert ( set<Key, Compare>::iterator pos,
Key k)
Inserts k in the set if k is not already present in S. The iterator pos is the starting point of the search. The return value points to the inserted item.
pair<set<Key, Compare>::iterator, bool>
S.insert ( Key k) Inserts k in the set if k is not already present in S. Returns a pair, where first is the iterator that points to the inserted item or to the item that is already present in S, and where second is true if the insertion took place.
void S.erase ( set<Key, Compare>::iterator pos)
Erases the element where pos points to.
int S.erase ( Key k) Erases the element k, if present. Returns the number of erased elements.

Miscellaneous

set<Key, Compare>::iterator
S.find ( Key k) Returns an iterator that either points to the element k, or end() if k is not present in set S.
int S.count ( Key k) Returns the number of occurrences of k in set S.
set<Key, Compare>::iterator
S.lower_bound ( Key k) Returns an iterator that points to the first element of S that is not less than k. If all elements are less than k then end() is returned. If k is present in the set the returned iterator points to k.
set<Key, Compare>::iterator
S.upper_bound ( Key k) Returns an iterator that points to the first element of the set that is greater than k. If no element is greater than k then end() is returned.


Next: Class declaration of multiset<Key, Compare>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Mon, June 30, 1997.