Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTValSet<T,C>

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/tvset.h> 
RWTValSet<T,C> s;

Standard C++ Library Dependent!


RWTValSet requires the Standard C++ Library.


Description

This class maintains a collection of values, which are ordered according to a comparison object of type C. C must induce a total ordering on elements of type T via a public member

bool operator()(const T& x, const T& y) const

which returns true if x should precede y within the collection. The structure less<T> from the C++-standard header file <functional> is an example.

RWTValSet<T,C> will not accept an item that compares equal to an item already in the collection. (RWTValMultiSet<T,C> may contain multiple items that compare equal to each other.) Equality is based on the comparison object and not on the == operator. Given a comparison object comp, items a and b are equal if

!comp(a,b) && !comp(b,a).

The value type must have operator== and operator< defined. This requirement is imposed by the Standard C++ Library.

Persistence

Isomorphic.

Examples

In this example, a set of RWCStrings is exercised.

//
// tvsstr.cpp
//
#include <rw/tvset.h>
#include <rw/cstring.h>
#include <iostream.h>
#include <function.h>

main(){
  RWTValSet<RWCString,less<RWCString> > set;

  set.insert("one");
  set.insert("two");
  set.insert("three");
  set.insert("one");     // Rejected: already in collection

  cout << set.entries() << endl;     // Prints "3"
  return 0;
}

Related Classes

Class RWTValMultiSet<T,C> offers the same interface to a collection that accepts multiple items that compare equal to each other. RWTValMap<K,T,C> maintains a collection of key-value pairs.

Class set<T,C,allocator> is the C++-standard collection that serves as the underlying implementation for RWTValSet<T,C>.

Public Typedefs

typedef set<T,C,allocator>                     container_type; 
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef container_type::size_type              size_type;
typedef:T                                      value_type; 
typedef const T&                               const_reference; 

Public Constructors

RWTValSet<T,C>(const C& comp = C());
RWTValSet<T,C>(const container_type& s);
RWTValSet<T,C>(const RWTValSet<T,C>& rws);
RWTValSet<T,C>
(const T* first,const T* last,const C& comp = C());

Public Member Operators

RWTValSet<T,C>&
operator=(const RWTValSet<T,C>& s); 
RWTValSet<T,C>&
operator=(const container_type& s);
bool
operator<(const RWTValSet<T,C>& s) const; 
bool
operator<(const container_type& s) const;
bool
operator==(const RWTValSet<T,C>& s) const; 
bool
operator==(const set<T,C>& s) const;

Public Member Functions

void
apply(void (*fn)(const_reference,void*), void* d) const; 
iterator
begin();
const_iterator
begin() const;
void
clear();
bool
contains(const_reference a) const; 
bool
contains(bool (*fn)(const_reference,void*), void* d) const; 
void
difference(const RWTValSet<T,C>& s); 
void
difference(const container_type& s);
iterator
end();
const_iterator
end() const;
size_type
entries() const; 
bool
find(const_reference a, T& k) const; 
bool
find(bool (*fn)(const_reference,void*), void* d, T& k) const;
bool
insert(const_reference a); 
void
intersection(const RWTValSet<T,C>& s); 
void
intersection(const container_type& s);
bool
isEmpty() const; 
bool
isEquivalent(const RWTValSet<T,C>& s) const; 
bool
isProperSubsetOf(const RWTValSet<T,C>& s) const; 
bool
isSubsetOf(const RWTValSet<T,C>& s) const; 
size_type
occurrencesOf(const_reference a) const; 
size_type
occurrencesOf(bool (*fn)(const T&,void*),void* d) const;
bool
remove(const_reference a); 
bool
remove(bool (*fn)(const_reference,void*), void* d);
size_type
removeAll(const_reference a); 
size_type
removeAll(bool (*fn)(const_reference,void*), void* d);
set<T,C,allocator>&
std();
const set<T,C,allocator>&
std() const;
void
symmetricDifference(const RWTValSet<T,C>& s); 
void
symmetricDifference(const container_type& s);
void
Union(const RWTValSet<T,C>& s); 
void
Union(const container_type& s);

Related Global Operators

RWvostream&
operator<<(RWvostream& strm, const RWTValSet<T,C>& coll); 
RWFile&
operator<<(RWFile& strm, const RWTValSet<T,C>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValSet<T,C>& coll); 
RWFile&
operator>>(RWFile& strm, RWTValSet<T,C>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValSet<T,C>*& p);
RWFile&
operator>>(RWFile& strm, RWTValSet<T,C>*& p);


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.