<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.programmingexamples.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=CPP%2FSTL%2FSet%2FBoundedInsert</id>
		<title>CPP/STL/Set/BoundedInsert - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=CPP%2FSTL%2FSet%2FBoundedInsert"/>
		<link rel="alternate" type="text/html" href="http://www.programmingexamples.net/w/index.php?title=CPP/STL/Set/BoundedInsert&amp;action=history"/>
		<updated>2026-05-25T00:05:48Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.5</generator>

	<entry>
		<id>http://www.programmingexamples.net/w/index.php?title=CPP/STL/Set/BoundedInsert&amp;diff=5173&amp;oldid=prev</id>
		<title>Daviddoria: Created page with '==BoundedInsert.cpp== &lt;source lang=&quot;cpp&quot;&gt; #include &lt;set&gt; #include &lt;iterator&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt;   template&lt;typename T&gt; std::set&lt;T&gt;&amp; bounded_insert(std::set&lt;…'</title>
		<link rel="alternate" type="text/html" href="http://www.programmingexamples.net/w/index.php?title=CPP/STL/Set/BoundedInsert&amp;diff=5173&amp;oldid=prev"/>
				<updated>2012-07-13T14:47:42Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;==BoundedInsert.cpp== &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; #include &amp;lt;set&amp;gt; #include &amp;lt;iterator&amp;gt; #include &amp;lt;iostream&amp;gt; #include &amp;lt;algorithm&amp;gt;   template&amp;lt;typename T&amp;gt; std::set&amp;lt;T&amp;gt;&amp;amp; bounded_insert(std::set&amp;lt;…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==BoundedInsert.cpp==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;set&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
template&amp;lt;typename T&amp;gt;&lt;br /&gt;
std::set&amp;lt;T&amp;gt;&amp;amp; bounded_insert(std::set&amp;lt;T&amp;gt;&amp;amp; s, std::size_t max, T val) {&lt;br /&gt;
    s.insert(val);&lt;br /&gt;
    while(s.size() &amp;gt; max) &lt;br /&gt;
        s.erase(std::max_element(s.begin(), s.end()));    &lt;br /&gt;
    return s;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
int main() {&lt;br /&gt;
    std::set&amp;lt;int&amp;gt; s;&lt;br /&gt;
    bounded_insert(s, 10, 0); &lt;br /&gt;
    bounded_insert(s, 10, 1); &lt;br /&gt;
    bounded_insert(s, 10, 3); &lt;br /&gt;
    bounded_insert(s, 10, 4); &lt;br /&gt;
    bounded_insert(s, 10, 5); &lt;br /&gt;
    bounded_insert(s, 10, 6); &lt;br /&gt;
    bounded_insert(s, 10, 7); &lt;br /&gt;
    bounded_insert(s, 10, 8); &lt;br /&gt;
    bounded_insert(s, 10, 9); &lt;br /&gt;
    bounded_insert(s, 10, 10);&lt;br /&gt;
    bounded_insert(s, 10, 2); &lt;br /&gt;
    bounded_insert(s, 10, 20);&lt;br /&gt;
    std::copy(s.begin(), s.end(), std::ostream_iterator&amp;lt;int&amp;gt;(std::cout, &amp;quot; &amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== CMakeLists.txt ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
cmake_minimum_required(VERSION 2.6)&lt;br /&gt;
&lt;br /&gt;
Project(BoundedInsert)&lt;br /&gt;
&lt;br /&gt;
ADD_EXECUTABLE(BoundedInsert BoundedInsert.cpp)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daviddoria</name></author>	</entry>

	</feed>