<?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::hash fuer QString (QT) in unordered_map]]></title><description><![CDATA[<p>Hi zusammen</p>
<p>ich habe in meiner Klasse eine unordered_map ( als Member ) fuer die ich die Hashfunktionen als Lambdas definieren möchte.</p>
<pre><code>private:
auto eq  = [](const QString &amp;key1, const QString &amp;key2){return key1 == key2; };
auto hs  = [](const QString &amp;key) { return std::hash&lt;std::string&gt;()( key.toStdString() ); };
std::unordered_map&lt;QString, std::shared_ptr&lt;MultiRow&gt;,  decltype(hs), decltype(eq)&gt; Data;
};
</code></pre>
<p>Leider akzeptiert der Compiler das ganz und gar nicht.</p>
<blockquote>
<p>Fehler: non-static data member declared 'auto'</p>
</blockquote>
<p>Ich habs auch mit <strong>static</strong> und <strong>constexpr</strong>. Fehlanzeige.</p>
<p>Geht das mit Lambdas bei einer Map als Member überhaupt, und wenn ja wie?<br />
Ich bin doch sicher nicht der erste, der für eine externe String-Klasse ( in dem Fall QTs QString ) die Hash-Funktionen definieren will, oder?</p>
<p>Dank &amp; Gruß</p>
<p>Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332192/std-hash-fuer-qstring-qt-in-unordered_map</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 05:14:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332192.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Apr 2015 05:46:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 05:46:19 GMT]]></title><description><![CDATA[<p>Hi zusammen</p>
<p>ich habe in meiner Klasse eine unordered_map ( als Member ) fuer die ich die Hashfunktionen als Lambdas definieren möchte.</p>
<pre><code>private:
auto eq  = [](const QString &amp;key1, const QString &amp;key2){return key1 == key2; };
auto hs  = [](const QString &amp;key) { return std::hash&lt;std::string&gt;()( key.toStdString() ); };
std::unordered_map&lt;QString, std::shared_ptr&lt;MultiRow&gt;,  decltype(hs), decltype(eq)&gt; Data;
};
</code></pre>
<p>Leider akzeptiert der Compiler das ganz und gar nicht.</p>
<blockquote>
<p>Fehler: non-static data member declared 'auto'</p>
</blockquote>
<p>Ich habs auch mit <strong>static</strong> und <strong>constexpr</strong>. Fehlanzeige.</p>
<p>Geht das mit Lambdas bei einer Map als Member überhaupt, und wenn ja wie?<br />
Ich bin doch sicher nicht der erste, der für eine externe String-Klasse ( in dem Fall QTs QString ) die Hash-Funktionen definieren will, oder?</p>
<p>Dank &amp; Gruß</p>
<p>Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450242</guid><dc:creator><![CDATA[It0101]]></dc:creator><pubDate>Wed, 15 Apr 2015 05:46:19 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 06:19:29 GMT]]></title><description><![CDATA[<p>Die direkte Art und Weise, die mir spontan einfällt, ist, einfach kein auto zu nutzen. Ein lambda ist ein Funktionsobjekt, also passt vom Typ her std::function&lt;passende argumente&gt;. Beispielsweise:</p>
<pre><code>#include &lt;functional&gt;

class X
{
 private:
  std::function&lt;void(int)&gt; foo = [](int a){return a+5;};
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2450248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450248</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 15 Apr 2015 06:19:29 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 07:54:48 GMT]]></title><description><![CDATA[<p>Sieht gut aus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> Compiler ist erstmal zufrieden. Ich gehe davon aus, dass die Map dann auch funzt.</p>
<p>Danke dir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450259</guid><dc:creator><![CDATA[It0101]]></dc:creator><pubDate>Wed, 15 Apr 2015 07:54:48 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 07:57:39 GMT]]></title><description><![CDATA[<p>Du könntest natürlich auch QHash verwenden. Das sollte mit QString ja direkt funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450260</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 15 Apr 2015 07:57:39 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 11:42:37 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Die direkte Art und Weise, die mir spontan einfällt, ist, einfach kein auto zu nutzen. Ein lambda ist ein Funktionsobjekt, also passt vom Typ her std::function&lt;passende argumente&gt;. Beispielsweise:</p>
<pre><code>#include &lt;functional&gt;

class X
{
 private:
  std::function&lt;void(int)&gt; foo = [](int a){return a+5;};
};
</code></pre>
</blockquote>
<p>Funktionszeiger sind aus der Mode?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450295</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 15 Apr 2015 11:42:37 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 15:58:32 GMT]]></title><description><![CDATA[<p>Da bin ich auch schon drüber gestolpert. auto funktioniert da nicht, den Typ einenes Lambdas kann man auch nicht direkt angeben, std::function will man wegen des Overheads eventuell auch nicht haben. Nicht sehr schön gelöst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450348</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 15 Apr 2015 15:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Wed, 15 Apr 2015 16:24:27 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich habs auch mit static und constexpr. Fehlanzeige.</p>
</blockquote>
<p>Äh, mit <code>static</code> gehts. Du musst natürlich die Hashfunktion im Konstruktor übergeben da closure Typen keine Defaultkonstruktoren haben, aber ansonsten sollte das problemlos kompilieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450353</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 15 Apr 2015 16:24:27 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Thu, 16 Apr 2015 07:39:50 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30768">@TNA</a>: mit welcher Art von Overhead habe ich bei std::function zu rechnen?</p>
<p>@Arcoth: wie würde deine Lösung mit Funktionszeigern aussehen?</p>
<p>Meine Lösung habe ich jetzt erstmal so:</p>
<pre><code>std::function&lt;bool(const QString &amp;,const QString &amp;)&gt; eq  = [](const QString &amp;key1, const QString &amp;key2){return key1 == key2; };
std::function&lt;bool(const QString &amp;)&gt; hs  = [](const QString &amp;key) { return std::hash&lt;std::string&gt;()( key.toStdString() ); };
std::unordered_map&lt;QString, std::shared_ptr&lt;MultiRow&gt;,  decltype(hs), decltype(eq)&gt; Data;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2450448</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450448</guid><dc:creator><![CDATA[It0101]]></dc:creator><pubDate>Thu, 16 Apr 2015 07:39:50 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Mon, 20 Apr 2015 05:51:36 GMT]]></title><description><![CDATA[<p>Jemand ne Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2450917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450917</guid><dc:creator><![CDATA[It0101]]></dc:creator><pubDate>Mon, 20 Apr 2015 05:51:36 GMT</pubDate></item><item><title><![CDATA[Reply to std::hash fuer QString (QT) in unordered_map on Mon, 20 Apr 2015 07:22:55 GMT]]></title><description><![CDATA[<p>Na, so:</p>
<pre><code>private:
  static constexpr auto eq  = [](const QString &amp;key1, const QString &amp;key2){return key1 == key2; };
  static constexpr auto hs  = [](const QString &amp;key) { return std::hash&lt;std::string&gt;()(key.toStdString() ); };
  std::unordered_map&lt;QString, std::shared_ptr&lt;MultiRow&gt;,  decltype(hs), decltype(eq)&gt; Data;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2450924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2450924</guid><dc:creator><![CDATA[funktionszeiger]]></dc:creator><pubDate>Mon, 20 Apr 2015 07:22:55 GMT</pubDate></item></channel></rss>