<?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[tr1::unordered_map mit zeigern]]></title><description><![CDATA[<p>Hallo ihr,<br />
ich habe ein Programm geschrieben, dass eine tr1::unordered_multimap verwendet.<br />
Aber ich habe das Gefühl, dass das Matching (in Form von find und equal_range) nicht funktioniert. Hier der kleinste Code wo das auftritt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;tr1/unordered_map&gt;

using namespace std;
using std::tr1::unordered_multimap;

struct inthash {
  size_t operator () (int* n) const {
    size_t seed = long(n) % 2;
    return seed;
  }
};

typedef unordered_multimap&lt;int*, int, inthash&gt; mm;

int main() {
  mm h;
  int* i1 = new int(3);
  h.insert(make_pair(i1, 3));
  int* i2 = new int(5);
  cout &lt;&lt; i1 &lt;&lt; &quot; &quot; &lt;&lt; i2 &lt;&lt; endl;

  std::pair&lt;mm::const_iterator, mm::const_iterator&gt; p = h.equal_range(i2);
  if (p.first == h.end()) {
    cout &lt;&lt; &quot;no matching\n&quot;;
  } else {
    cout &lt;&lt; &quot;found matching\n&quot;;
  }
  return 0;
}
</code></pre>
<p>Ich erzeuge zwei Int pointer und will sie zusammen hashen wenn beide eine gerade Adresse haben (siehe inthash).<br />
Allerdings ist die Ausgabe immer &quot;no matching&quot; auch wenn die beiden Adressen gerade waren.<br />
Könnt ihr euch das erklären?</p>
<p>Viele Grüße,<br />
Jean</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/245388/tr1-unordered_map-mit-zeigern</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 19:26:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/245388.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Jul 2009 15:29:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to tr1::unordered_map mit zeigern on Mon, 13 Jul 2009 15:29:32 GMT]]></title><description><![CDATA[<p>Hallo ihr,<br />
ich habe ein Programm geschrieben, dass eine tr1::unordered_multimap verwendet.<br />
Aber ich habe das Gefühl, dass das Matching (in Form von find und equal_range) nicht funktioniert. Hier der kleinste Code wo das auftritt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;tr1/unordered_map&gt;

using namespace std;
using std::tr1::unordered_multimap;

struct inthash {
  size_t operator () (int* n) const {
    size_t seed = long(n) % 2;
    return seed;
  }
};

typedef unordered_multimap&lt;int*, int, inthash&gt; mm;

int main() {
  mm h;
  int* i1 = new int(3);
  h.insert(make_pair(i1, 3));
  int* i2 = new int(5);
  cout &lt;&lt; i1 &lt;&lt; &quot; &quot; &lt;&lt; i2 &lt;&lt; endl;

  std::pair&lt;mm::const_iterator, mm::const_iterator&gt; p = h.equal_range(i2);
  if (p.first == h.end()) {
    cout &lt;&lt; &quot;no matching\n&quot;;
  } else {
    cout &lt;&lt; &quot;found matching\n&quot;;
  }
  return 0;
}
</code></pre>
<p>Ich erzeuge zwei Int pointer und will sie zusammen hashen wenn beide eine gerade Adresse haben (siehe inthash).<br />
Allerdings ist die Ausgabe immer &quot;no matching&quot; auch wenn die beiden Adressen gerade waren.<br />
Könnt ihr euch das erklären?</p>
<p>Viele Grüße,<br />
Jean</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1742225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1742225</guid><dc:creator><![CDATA[dschutschi]]></dc:creator><pubDate>Mon, 13 Jul 2009 15:29:32 GMT</pubDate></item><item><title><![CDATA[Reply to tr1::unordered_map mit zeigern on Mon, 13 Jul 2009 16:00:52 GMT]]></title><description><![CDATA[<p>Hi,<br />
hab das Problem gefunden:<br />
man muss noch eine equality selbst definieren, ansonsten vergleicht er standard-<br />
mäßig die adressen.</p>
<pre><code class="language-cpp">struct inteq {
  bool operator () (const T&amp; a, const T&amp; b) const {
    return *a == *b;
  }
};
typedef unordered_multimap&lt;T, int, inthash, inteq&gt; mm;
</code></pre>
<p>Jean</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1742251</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1742251</guid><dc:creator><![CDATA[dschutschi]]></dc:creator><pubDate>Mon, 13 Jul 2009 16:00:52 GMT</pubDate></item></channel></rss>