vector

set

The set class supports a set in which unique keys are mapped with values. Its template specification is shown here:

template <class Key, class Comp = less<Key>,
                class Allocator = allocator<Key> > class set

Here, Key is the data of the keys and Comp is a function that compares
two keys. It has the following constructors:

explicit set(const Comp &cmpfn = Comp( ),
                const Allocator &a = Allocator( ) );
set(const set<Key, Comp, Allocator> &ob);
template <class InIter> set(InIter start, InIter end,
                const Comp &cmpfn = Comp( ),
                const Allocator &a = Allocator( ));

The first form constructs an empty set. The second form constructs a set that contains the same elements as ob. The third form constructs a set that contains the elements in the range specified by start and end. The function specified by cmpfn, if present, determines the ordering of the set.

The following comparison operators are defined for set:

==, <, <=, !=, >, >=

The member functions contained by set are shown here:

Member

Description

iterator begin( );
const_iterator begin( ) const;

Returns an iterator to the first element in the set.

void clear( );

Removes all elements from the set.

size_type count(const key_type &k) const;

Returns the number of times k occurs in the set, which will be 0 or 1.

bool empty( ) const;

Returns true if the invoking set is empty and false otherwise.

const_iterator end( ) const;
iterator end( );

Returns an iterator to the end of the set.

pair<iterator, iterator>
   equal_range(const key_type &k) const;

Returns a pair of iterators that point to the first and last elements in the set that contain the specified key.

void erase(iterator i);

Removes the element pointed to by i.

void erase(iterator start, iterator end);

Removes the elements in the range start to end.

size_type erase(const key_type &k);

Removes from the set elements that have keys with the value k. The number of elements removed is returned.

iterator find(const key_type &k) const;

Returns an iterator to the specified key. If the key is not found, then an iterator to the end of the set is returned.

allocator_type get_allocator( ) const;

Returns set’s allocator.

iterator insert(iterator i,
                        const value_type &val);

Inserts val at or after the element specified by i. Duplicate elements are not inserted. An iterator to the element is returned.

template <class InIter>
   void insert(InIter start, InIter end);

Inserts a range of elements. Duplicate elements are not inserted.

pair<iterator, bool>
   insert(const value_type &val);

Inserts val into the invoking set. An iterator to the element is returned. The element is inserted only if it does not already exist. If the element was inserted, pair<iterator, true> is returned. Otherwise, pair<iterator, false> is returned.

iterator lower_bound(const key_type &k)
   const;

Returns an iterator to the first element in the set with the key equal to or greater than k.

key_compare key_comp( ) const;

Returns the function object that compares keys.

size_type max_size( ) const;

Returns the maximum number of elements that the set can hold.

reverse_iterator rbegin( );
const_reverse_iterator rbegin( ) const;

Returns a reverse iterator to the end of the set.

reverse_iterator rend( );
const_reverse_iterator rend( ) const;

Returns a reverse iterator to the start of the set.

size_type size( ) const;

Returns the number of elements currently in the set.

void swap(set<Key, Comp,Allocator> &ob);

Exchanges the elements stored in the invoking set with those in ob.

iterator upper_bound(const key_type &k)
   const;

Returns an iterator to the first element in the set with the key greater than k.

value_compare value_comp( ) const;

Returns the function object that compares values.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net