<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[std::map ohne less]]></title><description><![CDATA[<p>ich versuche in c++ eine struktur für eine diskrete mathematische funktion zu basteln. diskret in dem sinn, dass die ausgangsmenge endlich ist.</p>
<p>einzelne elemente dieser menge sind vom typ QPoint, für den nur ein operator== existiert, d.h. ich habe keine ordnungsrelation.</p>
<p>nun wollte ich für die zuordnung QPoint -&gt; float eine std::map nehmen, also<br />
std::map&lt;QPoint, float&gt;.</p>
<p>aber die braucht ja einen compare funktor, den ich ja nicht habe.</p>
<p>wie kann ich das problem am besten lösen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/247243/std-map-ohne-less</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 14:57:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/247243.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Aug 2009 09:15:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 09:15:09 GMT]]></title><description><![CDATA[<p>ich versuche in c++ eine struktur für eine diskrete mathematische funktion zu basteln. diskret in dem sinn, dass die ausgangsmenge endlich ist.</p>
<p>einzelne elemente dieser menge sind vom typ QPoint, für den nur ein operator== existiert, d.h. ich habe keine ordnungsrelation.</p>
<p>nun wollte ich für die zuordnung QPoint -&gt; float eine std::map nehmen, also<br />
std::map&lt;QPoint, float&gt;.</p>
<p>aber die braucht ja einen compare funktor, den ich ja nicht habe.</p>
<p>wie kann ich das problem am besten lösen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757263</guid><dc:creator><![CDATA[Jover]]></dc:creator><pubDate>Sat, 08 Aug 2009 09:15:09 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 09:24:05 GMT]]></title><description><![CDATA[<p>Was spricht dagegen, einfach eine Ordnungsrelation zu definieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757269</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sat, 08 Aug 2009 09:24:05 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 09:27:37 GMT]]></title><description><![CDATA[<p>Oder du verwendest eben z.B. std::equal_to als Vergleicher. Nur ist dein Baum dann eben nicht besonders gut aus balanciert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757271</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Sat, 08 Aug 2009 09:27:37 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 09:32:11 GMT]]></title><description><![CDATA[<p>Badestrand schrieb:</p>
<blockquote>
<p>Was spricht dagegen, einfach eine Ordnungsrelation zu definieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>weil eine ordnungsrelation einfach keinen sinn machen würde.</p>
<p>David_pb schrieb:</p>
<blockquote>
<p>Oder du verwendest eben z.B. std::equal_to als Vergleicher. Nur ist dein Baum dann eben nicht besonders gut aus balanciert.</p>
</blockquote>
<p>danke, werds mal probieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757273</guid><dc:creator><![CDATA[Jover]]></dc:creator><pubDate>Sat, 08 Aug 2009 09:32:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 09:50:50 GMT]]></title><description><![CDATA[<p>Jover schrieb:</p>
<blockquote>
<p>Badestrand schrieb:</p>
<blockquote>
<p>Was spricht dagegen, einfach eine Ordnungsrelation zu definieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>weil eine ordnungsrelation einfach keinen sinn machen würde.</p>
</blockquote>
<p>Ist doch egal, wird doch nur zum sortieren verwendet.</p>
<p>David_pb schrieb:</p>
<blockquote>
<p>Oder du verwendest eben z.B. std::equal_to als Vergleicher. Nur ist dein Baum dann eben nicht besonders gut aus balanciert.</p>
</blockquote>
<p>Hm, ich glaube der MSVC erwartet im Debug-Modus eine strikte Ordnung und prüft auf <code>if(rel(a,b)) assert(!rel(b,a));</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757284</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sat, 08 Aug 2009 09:50:50 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 10:16:09 GMT]]></title><description><![CDATA[<p>Badestrand schrieb:</p>
<blockquote>
<p>David_pb schrieb:</p>
<blockquote>
<p>Oder du verwendest eben z.B. std::equal_to als Vergleicher. Nur ist dein Baum dann eben nicht besonders gut aus balanciert.</p>
</blockquote>
<p>Hm, ich glaube der MSVC erwartet im Debug-Modus eine strikte Ordnung und prüft auf <code>if(rel(a,b)) assert(!rel(b,a));</code></p>
</blockquote>
<p>Der C++ Standard schreibt es sogar vor:</p>
<p>C++ Standard 14882:2003 - 23.1.2 Associative containers schrieb:</p>
<blockquote>
<p><sup>2</sup> Each associative container is parameterized on <code>Key</code> and an ordering relation <code>Compare</code> that induces a strict weak ordering (25.3) on elements of <code>Key</code> . In addition, <code>map</code> and <code>multimap</code> associate an arbitrary type <code>T</code> with the <code>Key</code> . The object of type <code>Compare</code> is called the comparison object of a container. This <em>comparison object</em> may be a pointer to function or an object of a type with an appropriate function call operator.</p>
<p><sup>3</sup> The phrase &quot;equivalence of keys&quot; means the equivalence relation imposed by the comparison and not the <code>operator==</code> on keys. That is, two keys <code>k1</code> and <code>k2</code> are considered to be equivalent if for the <em>comparison object</em> <code>comp, comp(k1, k2) == false &amp;&amp; comp(k2, k1) == false</code> .</p>
</blockquote>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757296</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 08 Aug 2009 10:16:09 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 14:14:38 GMT]]></title><description><![CDATA[<p>Wenn du die Ordnungsrelation nicht in deiner Punkt-Klasse haben möchtest, dann machs doch so in etwa:</p>
<pre><code class="language-cpp">#include &lt;set&gt;

struct point
{
	float x, y;
};

struct point_less
{
	bool operator() (const point &amp;lhs, const point &amp;rhs) const
	{
		if(lhs.x == rhs.x)
			return lhs.y &lt; rhs.y;
		else
			return lhs.x &lt; rhs.x;
	}
};

int main()
{
	std::set&lt;point, point_less&gt; my_map;
}
</code></pre>
<p>bb</p>
<p>edit: das gleiche geht natürlich auch mit map und nicht set^^ weiß auch nich so genau, wieso ich set genommen hatte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>edit: operator gebaut ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757362</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 08 Aug 2009 14:14:38 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 13:18:06 GMT]]></title><description><![CDATA[<p>ich fürchte, dass die QPoint klasse eine so komplexe struktur hat, dass eine strikte ordnung kaum darauf zu definieren ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757379</guid><dc:creator><![CDATA[Jover]]></dc:creator><pubDate>Sat, 08 Aug 2009 13:18:06 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 13:32:20 GMT]]></title><description><![CDATA[<p>Jover schrieb:</p>
<blockquote>
<p>ich fürchte, dass die QPoint klasse eine so komplexe struktur hat, dass eine strikte ordnung kaum darauf zu definieren ist.</p>
</blockquote>
<p>Deine Befürchtungen kann ich zersteuen:</p>
<pre><code class="language-cpp">bool less(QPoint const&amp; a,QPont const&amp; b){
   if(a.x&lt;b.x) return true;
   if(b.x&lt;a.x) return false;

   if(a.y&lt;b.y) return true;
   if(b.y&lt;a.y) return false;

   if(a.z&lt;b.z) return true;
   if(b.z&lt;a.z) return false;

   if(a.hue&lt;b.hue) return true;
   if(b.hue&lt;a.hue) return false;

   ...//noch 25854 andere attribute
   return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1757389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757389</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 08 Aug 2009 13:32:20 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 13:36:54 GMT]]></title><description><![CDATA[<blockquote>
<p>struct point_less<br />
{<br />
friend bool operator&lt; (const point &amp;lhs, const point &amp;rhs)</p>
</blockquote>
<p>() statt &lt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757392</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 08 Aug 2009 13:36:54 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 13:43:52 GMT]]></title><description><![CDATA[<p>Hast du schon einmal in Erwägung gezogen, dass std::map hier die falsche Struktur ist? Versuch es doch mal mit einer Hashtabelle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757396</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757396</guid><dc:creator><![CDATA[Tippgeber]]></dc:creator><pubDate>Sat, 08 Aug 2009 13:43:52 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 13:51:48 GMT]]></title><description><![CDATA[<p>hash_map -&gt; genau das was ich brauche.</p>
<p>danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757399</guid><dc:creator><![CDATA[Jover]]></dc:creator><pubDate>Sat, 08 Aug 2009 13:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 13:50:40 GMT]]></title><description><![CDATA[<p>Tippgeber schrieb:</p>
<blockquote>
<p>Hast du schon einmal in Erwägung gezogen, dass std::map hier die falsche Struktur ist? Versuch es doch mal mit einer Hashtabelle.</p>
</blockquote>
<p>Ob die Hashtable oder der Baum passender sind, hängt von den zu erwartenden Operationen ab, wie oft Einfügungen, Löschungen, Suchen?<br />
Außerdem: Manche Leute haben ein sehr schlechtes Gefühl beim Hashen von doubles, was vor allem Daran liegt, daß man sich alle Epsilon-Tests komplett verbaut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757401</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 08 Aug 2009 13:50:40 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 14:12:31 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<blockquote>
<p>struct point_less<br />
{<br />
friend bool operator&lt; (const point &amp;lhs, const point &amp;rhs)</p>
</blockquote>
<p>() statt &lt;</p>
</blockquote>
<p>korrekt, habs geändert ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757406</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 08 Aug 2009 14:12:31 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 14:22:55 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Tippgeber schrieb:</p>
<blockquote>
<p>Hast du schon einmal in Erwägung gezogen, dass std::map hier die falsche Struktur ist? Versuch es doch mal mit einer Hashtabelle.</p>
</blockquote>
<p>Ob die Hashtable oder der Baum passender sind, hängt von den zu erwartenden Operationen ab, wie oft Einfügungen, Löschungen, Suchen?<br />
Außerdem: Manche Leute haben ein sehr schlechtes Gefühl beim Hashen von doubles, was vor allem Daran liegt, daß man sich alle Epsilon-Tests komplett verbaut.</p>
</blockquote>
<p>Das ist ein Argument.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757411</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757411</guid><dc:creator><![CDATA[Tippgeber]]></dc:creator><pubDate>Sat, 08 Aug 2009 14:22:55 GMT</pubDate></item><item><title><![CDATA[Reply to std::map ohne less on Sat, 08 Aug 2009 18:25:38 GMT]]></title><description><![CDATA[<p>Was ich halt nicht machen würde, wäre einen Kleiner-Als-Operator für eine Punktklasse zu definieren. Aber gegen einen Funktor oder eine Funktion, die nur bei der Map angegeben wird und sonst nirgends für Verwirrung sorgt, spricht nichts.</p>
<p>Nur weil du zu faul bist, eine Ordnungsrelation zu definieren, solltest du nicht auf Hash-Maps wechseln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1757541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1757541</guid><dc:creator><![CDATA[Der Antworter]]></dc:creator><pubDate>Sat, 08 Aug 2009 18:25:38 GMT</pubDate></item></channel></rss>