<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chys&#039;s random notes &#187; STL</title>
	<atom:link href="http://en.chys.info/tag/stl/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.chys.info</link>
	<description>Study more problems; Talk less of isms.</description>
	<lastBuildDate>Tue, 27 Dec 2011 11:56:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>std::hash&lt;std::string&gt;</title>
		<link>http://en.chys.info/2009/10/stdhashstdstring/</link>
		<comments>http://en.chys.info/2009/10/stdhashstdstring/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 14:12:00 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++0x]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[STL]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=676</guid>
		<description><![CDATA[TR1 requires std::tr1::hash (std::hash in C++0x) to be instantiable for integer/floating point types, std::string and std::wstring. (C++0x added std::error_code, std::thread:id, std::bitset, std::u16string, std::u32string, and std::vector&#60;bool&#62;.) But for strings, every call to std::hash&#60;string&#62;::operator()(std::string) incurs an unnecessary copy construction, which can be expensive in implementations where std::basic_string does not use COW. Developers of GCC are apparently aware [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/07/string-literals/' rel='bookmark' title='String literals'>String literals</a></li>
<li><a href='http://en.chys.info/2009/11/an-rvalue-reference-issue/' rel='bookmark' title='An Rvalue Reference Issue'>An Rvalue Reference Issue</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/C%2B%2B_Technical_Report_1">TR1</a> requires <code>std::tr1::hash</code> (<code>std::hash</code> in C++0x) to be instantiable for integer/floating point types, <code>std::string</code> and <code>std::wstring</code>. (C++0x added <code>std::error_code</code>, <code>std::thread:id</code>, <code>std::bitset</code>, <code>std::u16string</code>, <code>std::u32string</code>, and <code>std::vector&lt;bool&gt;</code>.)</p>
<p>But for strings, every call to <code>std::hash&lt;string&gt;::operator()(std::string)</code> incurs an unnecessary copy construction, which can be expensive in implementations where <code>std::basic_string</code> does not use <a href="http://en.wikipedia.org/wiki/Copy-on-write">COW</a>.</p>
<p>Developers of GCC are apparently aware of this, and they added specializations <code>std::hash&lt;const std::string &amp;&gt;</code> and <code>std::hash&lt;const std::wstring &amp;&gt;</code> starting from GCC 4.3.</p>
<p>However, I still guess we cannot easily benefit from this since we will need to write something like this:</p>
<blockquote><pre>
std::unordered_set&lt;std::string, std::hash&lt;const std::string &amp;&gt;&gt;
</pre>
</blockquote>
<p>(In C++0x it&#8217;s no longer required to insert a space between the two larger-than characters.)</p>
<p>Too ugly and inconvenient to use, unless our program is really time critical.</p>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/07/string-literals/' rel='bookmark' title='String literals'>String literals</a></li>
<li><a href='http://en.chys.info/2009/11/an-rvalue-reference-issue/' rel='bookmark' title='An Rvalue Reference Issue'>An Rvalue Reference Issue</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/10/stdhashstdstring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

