 <p>(My second attempt at the answer.)</p> <p>This is rather an elaboration of Anthony Williams's answer.</p> <p>Both iterators that you need are available in the Boost libraries (your own myIter is lacking functionality which may make your code uncompilable with other compilers).</p> <pre><code>#include &lt;set&gt; #include &lt;algorithm&gt; #include &lt;iostream&gt; #include &lt;boost/iterator/counting_iterator.hpp&gt; #include &lt;boost/iterator/transform_iterator.hpp&gt; #include &lt;boost/mem_fn.hpp&gt; struct point { point(int X, int Y):x(X), y(Y){} int x; int y; }; bool operator&lt; (const point&amp; a, const point&amp; b) { return a.x &lt; b.x || (a.x == b.x &amp;&amp; a.y &lt; b.y); } int main() { std::set &lt;point&gt; myset; myset.insert(point(1, 1)); myset.insert(point(3, 2)); myset.insert(point(5, 3)); //find the missing elements in set for `point.x` using `set_difference` std::set&lt;int&gt; missing; using namespace boost; std::set_difference( counting_iterator&lt;int&gt;(myset.begin()-&gt;x+1), counting_iterator&lt;int&gt;(myset.rbegin()-&gt;x), make_transform_iterator( myset.begin(), mem_fn(&amp;point::x)), make_transform_iterator( myset.end(), mem_fn(&amp;point::x)), std::inserter(missing, missing.begin())); std::copy(missing.begin(), missing.end(), std::ostream_iterator&lt;int&gt;(std::cout, " ")); } </code></pre> <p>Points of interest:</p> <ul> <li><code>point</code> needs to be "less-than" comparable, if you want to store them in a <code>set</code></li> <li><code>boost::counting_iterator</code> is a better <code>myIter</code></li> <li><code>boost::transform_iterator</code> allows you to apply a function to the value when dereferenced. In combination with <code>boost::mem_fn</code> it obtains the <code>Point::x</code> member when the iterator is dereferenced.</li> <li>use the helper function <code>std::inserter</code> to get the template arguments deduced</li> <li>the results don't have to be stored in a <code>set</code> (neither does the input have to come from a <code>set</code>, as long as the range is sorted with respect to the used predicate - here comparing the x member.</li> </ul>