<p>I am trying to use <code>set.insert (key)</code> as a conditional, where if the key is inserted correctly (meaning that the key does NOT already exist in the set ) then it should go on and perform some kind of code. For example, something like:</p>

<pre><code>if (set.insert( key )) {
    // some kind of code
}
</code></pre>

<p>Is this allowed? Because the compiler is throwing this error: </p>

<pre><code>conditional expression of type 'std::_Tree&lt;_Traits&gt;::iterator' is illegal
</code></pre>

set::insert returns a pair, try this:
```
```
if( set.insert( key ).second ) {
    // some kind of code
}
```
```