aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/ext/vstring.h60
-rw-r--r--libstdc++-v3/testsuite/ext/vstring/hash/char/1.cc55
-rw-r--r--libstdc++-v3/testsuite/ext/vstring/hash/wchar_t/1.cc55
4 files changed, 179 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 3e606d2..a72c1bf 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2011-02-16 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR libstdc++/47773
+ * include/ext/vstring.h (hash<__gnu_cxx::__vstring>,
+ hash<__gnu_cxx::__wvstring>, hash<__gnu_cxx::__u16vstring>,
+ hash<__gnu_cxx::__u32vstring>): Add.
+ * testsuite/ext/vstring/hash/char/1.cc: New.
+ * testsuite/ext/vstring/hash/wchar_t/1.cc: Likewise.
+
2011-02-16 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/bits/regex.h (match_results::format): Use char_traits.
diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h
index 4695978..6e43e2b 100644
--- a/libstdc++-v3/include/ext/vstring.h
+++ b/libstdc++-v3/include/ext/vstring.h
@@ -2731,6 +2731,66 @@ _GLIBCXX_END_NAMESPACE_VERSION
#endif
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+#include <bits/functional_hash.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ /// std::hash specialization for __vstring.
+ template<>
+ struct hash<__gnu_cxx::__vstring>
+ : public __hash_base<size_t, __gnu_cxx::__vstring>
+ {
+ size_t
+ operator()(const __gnu_cxx::__vstring& __s) const
+ { return std::_Hash_impl::hash(__s.data(), __s.length()); }
+ };
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ /// std::hash specialization for __wvstring.
+ template<>
+ struct hash<__gnu_cxx::__wvstring>
+ : public __hash_base<size_t, __gnu_cxx::__wvstring>
+ {
+ size_t
+ operator()(const __gnu_cxx::__wvstring& __s) const
+ { return std::_Hash_impl::hash(__s.data(),
+ __s.length() * sizeof(wchar_t)); }
+ };
+#endif
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ /// std::hash specialization for __u16vstring.
+ template<>
+ struct hash<__gnu_cxx::__u16vstring>
+ : public __hash_base<size_t, __gnu_cxx::__u16vstring>
+ {
+ size_t
+ operator()(const __gnu_cxx::__u16vstring& __s) const
+ { return std::_Hash_impl::hash(__s.data(),
+ __s.length() * sizeof(char16_t)); }
+ };
+
+ /// std::hash specialization for __u32vstring.
+ template<>
+ struct hash<__gnu_cxx::__u32vstring>
+ : public __hash_base<size_t, __gnu_cxx::__u32vstring>
+ {
+ size_t
+ operator()(const __gnu_cxx::__u32vstring& __s) const
+ { return std::_Hash_impl::hash(__s.data(),
+ __s.length() * sizeof(char32_t)); }
+ };
+#endif
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+
+#endif /* __GXX_EXPERIMENTAL_CXX0X__ */
+
#include "vstring.tcc"
#endif /* _VSTRING_H */
diff --git a/libstdc++-v3/testsuite/ext/vstring/hash/char/1.cc b/libstdc++-v3/testsuite/ext/vstring/hash/char/1.cc
new file mode 100644
index 0000000..52140fc
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/vstring/hash/char/1.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <ext/vstring.h>
+#include <unordered_map>
+#include <testsuite_hooks.h>
+
+// libstdc++/47773
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef __gnu_cxx::__vstring vstring_t;
+ typedef std::unordered_map<vstring_t, int> map_t;
+
+ map_t mymap;
+
+ mymap.insert(std::make_pair("hello", 10));
+ mymap.insert(std::make_pair("hi", 20));
+
+ VERIFY( mymap.size() == 2 );
+
+ map_t::const_iterator imap = mymap.begin();
+
+ VERIFY( vstring_t(imap->first.c_str()) == "hi" );
+ VERIFY( imap->second == 20 );
+
+ ++imap;
+
+ VERIFY( vstring_t(imap->first.c_str()) == "hello" );
+ VERIFY( imap->second == 10 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/vstring/hash/wchar_t/1.cc b/libstdc++-v3/testsuite/ext/vstring/hash/wchar_t/1.cc
new file mode 100644
index 0000000..a5339d1
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/vstring/hash/wchar_t/1.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <ext/vstring.h>
+#include <unordered_map>
+#include <testsuite_hooks.h>
+
+// libstdc++/47773
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef __gnu_cxx::__wvstring vstring_t;
+ typedef std::unordered_map<vstring_t, int> map_t;
+
+ map_t mymap;
+
+ mymap.insert(std::make_pair(L"hello", 10));
+ mymap.insert(std::make_pair(L"hi", 20));
+
+ VERIFY( mymap.size() == 2 );
+
+ map_t::const_iterator imap = mymap.begin();
+
+ VERIFY( vstring_t(imap->first.c_str()) == L"hi" );
+ VERIFY( imap->second == 20 );
+
+ ++imap;
+
+ VERIFY( vstring_t(imap->first.c_str()) == L"hello" );
+ VERIFY( imap->second == 10 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}