set::reference

A type that provides a reference to an element stored in a set.

typedef typename allocator_type::reference reference;

Example

// set_reference.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1;

   s1.insert( 10 );
   s1.insert( 20 );

   // Declare and initialize a reference &Ref1 to the 1st element
   int &Ref1 = *s1.begin( );

   cout << "The first element in the set is "
        << Ref1 << "." << endl;

   // The value of the 1st element of the set can be changed
   // by operating on its (non const) reference
   Ref1 = Ref1 + 5;

   cout << "The first element in the set is now "
        << *s1.begin( ) << "." << endl;
}

The first element in the set is 10.
The first element in the set is now 15.

Requirements

Header: <set>

Namespace: std

See Also

Concepts

set Class

set Members

Standard Template Library