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

	<entry>
		<id>http://programmingexamples.net/w/index.php?title=CPP/STL/Set/SetCustomComparison&amp;diff=620&amp;oldid=prev</id>
		<title>Daviddoria: Created page with '==SetCustomComparison.cpp== &lt;source lang=&quot;cpp&quot;&gt; #include &lt;iostream&gt; #include &lt;set&gt; #include &lt;cmath&gt;  // Don't allow elements that are within 'tolerance' of each other to be added…'</title>
		<link rel="alternate" type="text/html" href="http://programmingexamples.net/w/index.php?title=CPP/STL/Set/SetCustomComparison&amp;diff=620&amp;oldid=prev"/>
				<updated>2011-01-30T15:07:22Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;==SetCustomComparison.cpp== &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; #include &amp;lt;iostream&amp;gt; #include &amp;lt;set&amp;gt; #include &amp;lt;cmath&amp;gt;  // Don&amp;#039;t allow elements that are within &amp;#039;tolerance&amp;#039; of each other to be added…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==SetCustomComparison.cpp==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;set&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Don't allow elements that are within 'tolerance' of each other to be added to the set&lt;br /&gt;
struct MyComparison&lt;br /&gt;
{&lt;br /&gt;
  bool operator()(const float s1, const float s2) const&lt;br /&gt;
  {&lt;br /&gt;
    double tolerance = 1e-4;&lt;br /&gt;
    if((s1 &amp;lt; s2) &amp;amp;&amp;amp; !( fabs(s1 - s2) &amp;lt; tolerance))&lt;br /&gt;
    {&lt;br /&gt;
      return true;&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
      return false;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[])&lt;br /&gt;
{&lt;br /&gt;
  std::set&amp;lt;float, MyComparison&amp;gt; S;&lt;br /&gt;
&lt;br /&gt;
  // Add 10 integers (0 to 9) to the set&lt;br /&gt;
  for(unsigned int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
  {&lt;br /&gt;
    S.insert(static_cast&amp;lt;float&amp;gt;(i));&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // Output all of the elements in the set&lt;br /&gt;
  for(std::set&amp;lt;float&amp;gt;::iterator it1 = S.begin(); it1 != S.end(); it1++)&lt;br /&gt;
  {&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; *it1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&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(SetCustomComparison)&lt;br /&gt;
&lt;br /&gt;
ADD_EXECUTABLE(SetCustomComparison SetCustomComparison.cpp)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daviddoria</name></author>	</entry>

	</feed>