Set constructors & destructors

Syntax:

    #include <set>
    set();
    set( const set& c );
    set( input_iterator start, input_iterator end );
    set( input_iterator start, input_iterator end, const key_compare& cmp );
    explicit set( const key_compare& cmp );
    ~set();

Every set has a default constructor, copy constructor, and destructor.

The default constructor takes no arguments, creates a new instance of that set, and runs in constant time. The default copy constructor runs in linear time and can be used to create a new set that is a copy of the given set c.

The default destructor is called when the set should be destroyed.

For example, the following code creates and displays a set of integers:

  const int max_nums = 10;
  int nums[max_nums] = {3,1,4,1,5,9,2,6,5,8};
 
  set<int> digits;
  for( int i = 0; i < max_nums; ++i ) digits.insert(nums[i]);
 
  cout << "Unique digits are: ";
  for( set<int>::const_iterator iter = digits.begin();
       iter != digits.end();
       ++iter ) {
    cout << *iter << ' ';
  }
  cout << '\n';

When run, this code displays:

Unique digits are: 1 2 3 4 5 6 8 9