<?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[Gibt es eine Methode at() in std::map?]]></title><description><![CDATA[<p>Guten Abend zusammen,</p>
<p>ich würde gerne folgendes machen</p>
<pre><code class="language-cpp">string foo(const map&lt;string,string&gt;&amp; m){
  return m.at(&quot;test&quot;);
}
</code></pre>
<p>und das wird vom gcc auch problemlos geschluckt.</p>
<p>Allerdings bin ich etwas verwundert, daß ich im Standard keine entsprechende Methode gefunden habe.<br />
Habe ich nur schlecht gesucht?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/284732/gibt-es-eine-methode-at-in-std-map</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 20:13:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/284732.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Apr 2011 20:04:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:04:19 GMT]]></title><description><![CDATA[<p>Guten Abend zusammen,</p>
<p>ich würde gerne folgendes machen</p>
<pre><code class="language-cpp">string foo(const map&lt;string,string&gt;&amp; m){
  return m.at(&quot;test&quot;);
}
</code></pre>
<p>und das wird vom gcc auch problemlos geschluckt.</p>
<p>Allerdings bin ich etwas verwundert, daß ich im Standard keine entsprechende Methode gefunden habe.<br />
Habe ich nur schlecht gesucht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045693</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045693</guid><dc:creator><![CDATA[thomas___]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:04:19 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:09:25 GMT]]></title><description><![CDATA[<p>Schau doch z.B. in der C++ Reference nach: <a href="http://www.cplusplus.com/reference/stl/map/" rel="nofollow">http://www.cplusplus.com/reference/stl/map/</a></p>
<p>Mein Compiler hat aber auch at() Ich kanns dir also nicht beantworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045699</guid><dc:creator><![CDATA[HighLigerBiMBam]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:09:25 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:08:26 GMT]]></title><description><![CDATA[<p>Naja, <a href="http://www.cplusplus.com/reference/stl/map/" rel="nofollow">hier</a> habe ich auch nichts gefunden. Aber ich arbeite immer ungeschützt (also <code>operator[]</code> ).</p>
<p>MfG, EOutOfResources</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045700</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:08:26 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:09:41 GMT]]></title><description><![CDATA[<p><a href="http://ideone.com/OaCKQ" rel="nofollow">http://ideone.com/OaCKQ</a><br />
Edit: @Vorposter: Falsch, operator [] kann auf eine const map nicht verwendet werden, der fügt nämlich ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045701</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:09:41 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:12:29 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Aber ich arbeite immer ungeschützt (also <code>operator[]</code> ).</p>
</blockquote>
<p>In der map&lt;&gt; ist der Index-Operator nicht wirklich &quot;ungeschützt&quot; - wenn du damit ein Element holst, das nicht existiert, wird es für dich angelegt (mit default-konstruiertem Wert).</p>
<p>Eine Methode at() gibt es offiziell nur für vector&lt;&gt;, deque&lt;&gt; und basic_string&lt;&gt;, wo du darauf aufpassen mußt, ob du im gültigen Bereich zugreifst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045704</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:12:29 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:14:15 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>EOutOfResources schrieb:</p>
<blockquote>
<p>wenn du damit ein Element holst, das nicht existiert, wird es für dich angelegt (mit default-konstruiertem Wert).</p>
</blockquote>
</blockquote>
<p>Wusste ich nicht. Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045707</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Wed, 06 Apr 2011 20:17:00 GMT]]></title><description><![CDATA[<p>Mein Compiler (MSVC2010) hat für at() diese Implementation:</p>
<pre><code class="language-cpp">#if _HAS_CPP0X
	mapped_type&amp; at(const key_type&amp; _Keyval)
		{	// find element matching _Keyval
		iterator _Where = this-&gt;lower_bound(_Keyval);
		if (_Where == this-&gt;end()
			|| this-&gt;comp(_Keyval, this-&gt;_Key(_Where._Mynode())))
			_Xout_of_range(&quot;invalid map&lt;K, T&gt; key&quot;);
		return ((*_Where).second);
		}

	const mapped_type&amp; at(const key_type&amp; _Keyval) const
		{	// find element matching _Keyval
		const_iterator _Where = this-&gt;lower_bound(_Keyval);
		if (_Where == this-&gt;end()
			|| this-&gt;comp(_Keyval, this-&gt;_Key(_Where._Mynode())))
			_Xout_of_range(&quot;invalid map&lt;K, T&gt; key&quot;);
		return ((*_Where).second);
		}
 #endif /* _HAS_CPP0X */
</code></pre>
<p>Eventuell kommt es durch C++0x.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045710</guid><dc:creator><![CDATA[HighLigerBiMBam]]></dc:creator><pubDate>Wed, 06 Apr 2011 20:17:00 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es eine Methode at() in std::map? on Thu, 07 Apr 2011 07:02:16 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p><a href="http://ideone.com/OaCKQ" rel="nofollow">http://ideone.com/OaCKQ</a></p>
</blockquote>
<p>Danke 314159265358979!</p>
<p>Ich war auf das Problem gestoßen, weil ich die (vermeintliche) exception von at() abfangen wollte.</p>
<p>find() macht genau das, was ich will und ich brauche noch nicht einmal eine exception abfangen, sondern kann auf !end() testen.</p>
<p>Im Nachhinein erscheint mir auch nachvollziehbar, warum die Methode nicht at() benannt wurde, denn die Semantik unterscheidet sich bei einem Nichttreffer ja doch sehr von vector::at().</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2045803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2045803</guid><dc:creator><![CDATA[thomas___]]></dc:creator><pubDate>Thu, 07 Apr 2011 07:02:16 GMT</pubDate></item></channel></rss>