diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-18 12:37:06 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-18 12:37:06 +0000 |
commit | d377f16447d0284433449fcccdba8efe2186c56b (patch) | |
tree | c112cd81959516415afee24bcf522b75fcf6693a /libstdc++-v3 | |
parent | 4ca9112cae18ffc6617405aef389219ac7321004 (diff) | |
download | gcc-d377f16447d0284433449fcccdba8efe2186c56b.tar.gz |
2011-11-18 Paolo Carlini <paolo.carlini@oracle.com>
* src/hash-long-double-aux.cc: Rename to...
* src/hash-long-double-tr1-aux.cc: ... this.
* src/compatibility-ldbl.cc: Adjust.
* src/hash_tr1.cc: Likewise.
* src/hash_c++0x.cc: Don't use src/hash-long-double-aux.cc.
* include/bits/functional_hash.h (hash<_Tp*>::operator(), specs
for integer types, hash<float>::operator(), hash<double>::operator(),
hash<long double>::operator()): Declare noexcept.
* include/debug/bitset (hash<__debug::bitset>::operator()): Likewise.
* include/debug/vector (hash<__debug::vector>::operator()): Likewise.
* include/std/system_error (hash<error_code>::operator()): Likewise.
* include/std/thread (hash<thread::id>::operator()): Likewise.
* include/std/bitset (hash<bitset>::operator()): Likewise.
* include/std/typeindex (hash<type_index>::operator()): Likewise.
* include/profile/bitset (hash<__profile::vector>::operator()):
Likewise.
* include/profile/vector (hash<__profile::vector>::operator()):
Likewise.
* include/ext/vstring.h (hash<__vstring>::operator(),
hash<__wvstring>::operator(), hash<__u16vstring>::operator(),
hash<__u32vstring>::operator()): Likewise.
* include/bits/shared_ptr.h (hash<shared_ptr>::operator()): Likewise.
* include/bits/shared_ptr_base.h (hash<__shared_ptr>::operator()):
Likewise.
* include/bits/unique_ptr.h (hash<unique_ptr>::operator()): Likewise.
* include/bits/basic_string.h (hash<string>::operator(),
hash<wstring>::operator(), hash<u16string>::operator(),
hash<u32string>::operator()): Likewise.
* include/bits/vector.tcc (hash<vector>::operator()): Likewise.
* include/bits/stl_bvector.h (hash<vector>::operator()): Likewise.
* libsupc++/typeinfo (type_info::hash_code): Use noexcept instead of
throw().
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181473 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
23 files changed, 188 insertions, 119 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c52db389583..0d68464933c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,38 @@ +2011-11-18 Paolo Carlini <paolo.carlini@oracle.com> + + * src/hash-long-double-aux.cc: Rename to... + * src/hash-long-double-tr1-aux.cc: ... this. + * src/compatibility-ldbl.cc: Adjust. + * src/hash_tr1.cc: Likewise. + * src/hash_c++0x.cc: Don't use src/hash-long-double-aux.cc. + * include/bits/functional_hash.h (hash<_Tp*>::operator(), specs + for integer types, hash<float>::operator(), hash<double>::operator(), + hash<long double>::operator()): Declare noexcept. + * include/debug/bitset (hash<__debug::bitset>::operator()): Likewise. + * include/debug/vector (hash<__debug::vector>::operator()): Likewise. + * include/std/system_error (hash<error_code>::operator()): Likewise. + * include/std/thread (hash<thread::id>::operator()): Likewise. + * include/std/bitset (hash<bitset>::operator()): Likewise. + * include/std/typeindex (hash<type_index>::operator()): Likewise. + * include/profile/bitset (hash<__profile::vector>::operator()): + Likewise. + * include/profile/vector (hash<__profile::vector>::operator()): + Likewise. + * include/ext/vstring.h (hash<__vstring>::operator(), + hash<__wvstring>::operator(), hash<__u16vstring>::operator(), + hash<__u32vstring>::operator()): Likewise. + * include/bits/shared_ptr.h (hash<shared_ptr>::operator()): Likewise. + * include/bits/shared_ptr_base.h (hash<__shared_ptr>::operator()): + Likewise. + * include/bits/unique_ptr.h (hash<unique_ptr>::operator()): Likewise. + * include/bits/basic_string.h (hash<string>::operator(), + hash<wstring>::operator(), hash<u16string>::operator(), + hash<u32string>::operator()): Likewise. + * include/bits/vector.tcc (hash<vector>::operator()): Likewise. + * include/bits/stl_bvector.h (hash<vector>::operator()): Likewise. + * libsupc++/typeinfo (type_info::hash_code): Use noexcept instead of + throw(). + 2011-11-17 Richard Henderson <rth@redhat.com> PR libstdc++/51181 diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 00f9bccd419..169daf58613 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -3044,7 +3044,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, string> { size_t - operator()(const string& __s) const + operator()(const string& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length()); } }; @@ -3055,7 +3055,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, wstring> { size_t - operator()(const wstring& __s) const + operator()(const wstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } }; @@ -3069,7 +3069,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, u16string> { size_t - operator()(const u16string& __s) const + operator()(const u16string& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char16_t)); } }; @@ -3080,7 +3080,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, u32string> { size_t - operator()(const u32string& __s) const + operator()(const u32string& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char32_t)); } }; diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h index e77cb4e17bf..2b82b21f716 100644 --- a/libstdc++-v3/include/bits/functional_hash.h +++ b/libstdc++-v3/include/bits/functional_hash.h @@ -66,61 +66,64 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<_Tp*> : public __hash_base<size_t, _Tp*> { size_t - operator()(_Tp* __p) const + operator()(_Tp* __p) const noexcept { return reinterpret_cast<size_t>(__p); } }; // Explicit specializations for integer types. #define _Cxx_hashtable_define_trivial_hash(_Tp) \ template<> \ - inline size_t \ - hash<_Tp>::operator()(_Tp __val) const \ - { return static_cast<size_t>(__val); } + struct hash<_Tp> : public __hash_base<size_t, _Tp> \ + { \ + size_t \ + operator()(_Tp __val) const noexcept \ + { return static_cast<size_t>(__val); } \ + }; /// Explicit specialization for bool. - _Cxx_hashtable_define_trivial_hash(bool); + _Cxx_hashtable_define_trivial_hash(bool) /// Explicit specialization for char. - _Cxx_hashtable_define_trivial_hash(char); + _Cxx_hashtable_define_trivial_hash(char) /// Explicit specialization for signed char. - _Cxx_hashtable_define_trivial_hash(signed char); + _Cxx_hashtable_define_trivial_hash(signed char) /// Explicit specialization for unsigned char. - _Cxx_hashtable_define_trivial_hash(unsigned char); + _Cxx_hashtable_define_trivial_hash(unsigned char) /// Explicit specialization for wchar_t. - _Cxx_hashtable_define_trivial_hash(wchar_t); + _Cxx_hashtable_define_trivial_hash(wchar_t) /// Explicit specialization for char16_t. - _Cxx_hashtable_define_trivial_hash(char16_t); + _Cxx_hashtable_define_trivial_hash(char16_t) /// Explicit specialization for char32_t. - _Cxx_hashtable_define_trivial_hash(char32_t); + _Cxx_hashtable_define_trivial_hash(char32_t) /// Explicit specialization for short. - _Cxx_hashtable_define_trivial_hash(short); + _Cxx_hashtable_define_trivial_hash(short) /// Explicit specialization for int. - _Cxx_hashtable_define_trivial_hash(int); + _Cxx_hashtable_define_trivial_hash(int) /// Explicit specialization for long. - _Cxx_hashtable_define_trivial_hash(long); + _Cxx_hashtable_define_trivial_hash(long) /// Explicit specialization for long long. - _Cxx_hashtable_define_trivial_hash(long long); + _Cxx_hashtable_define_trivial_hash(long long) /// Explicit specialization for unsigned short. - _Cxx_hashtable_define_trivial_hash(unsigned short); + _Cxx_hashtable_define_trivial_hash(unsigned short) /// Explicit specialization for unsigned int. - _Cxx_hashtable_define_trivial_hash(unsigned int); + _Cxx_hashtable_define_trivial_hash(unsigned int) /// Explicit specialization for unsigned long. - _Cxx_hashtable_define_trivial_hash(unsigned long); + _Cxx_hashtable_define_trivial_hash(unsigned long) /// Explicit specialization for unsigned long long. - _Cxx_hashtable_define_trivial_hash(unsigned long long); + _Cxx_hashtable_define_trivial_hash(unsigned long long) #undef _Cxx_hashtable_define_trivial_hash @@ -162,26 +165,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Specialization for float. template<> - inline size_t - hash<float>::operator()(float __val) const + struct hash<float> : public __hash_base<size_t, float> { - // 0 and -0 both hash to zero. - return __val != 0.0f ? std::_Hash_impl::hash(__val) : 0; - } + size_t + operator()(float __val) const noexcept + { + // 0 and -0 both hash to zero. + return __val != 0.0f ? std::_Hash_impl::hash(__val) : 0; + } + }; /// Specialization for double. template<> - inline size_t - hash<double>::operator()(double __val) const + struct hash<double> : public __hash_base<size_t, double> { - // 0 and -0 both hash to zero. - return __val != 0.0 ? std::_Hash_impl::hash(__val) : 0; - } + size_t + operator()(double __val) const noexcept + { + // 0 and -0 both hash to zero. + return __val != 0.0 ? std::_Hash_impl::hash(__val) : 0; + } + }; /// Specialization for long double. template<> - _GLIBCXX_PURE size_t - hash<long double>::operator()(long double __val) const; + struct hash<long double> + : public __hash_base<size_t, long double> + { + _GLIBCXX_PURE size_t + operator()(long double __val) const noexcept; + }; // @} group hashes diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 32addf95105..33128dd4ed6 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -619,7 +619,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, shared_ptr<_Tp>> { size_t - operator()(const shared_ptr<_Tp>& __s) const + operator()(const shared_ptr<_Tp>& __s) const noexcept { return std::hash<_Tp*>()(__s.get()); } }; diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index fbbadd1aaaa..c0677547553 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1450,7 +1450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, __shared_ptr<_Tp, _Lp>> { size_t - operator()(const __shared_ptr<_Tp, _Lp>& __s) const + operator()(const __shared_ptr<_Tp, _Lp>& __s) const noexcept { return std::hash<_Tp*>()(__s.get()); } }; diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 8f286400aec..bec63ff03f9 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -1075,7 +1075,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, _GLIBCXX_STD_C::vector<bool, _Alloc>> { size_t - operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const; + operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>&) const noexcept; }; _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 869d931330c..0a127996e52 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -545,7 +545,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, unique_ptr<_Tp, _Dp>> { size_t - operator()(const unique_ptr<_Tp, _Dp>& __u) const + operator()(const unique_ptr<_Tp, _Dp>& __u) const noexcept { typedef unique_ptr<_Tp, _Dp> _UP; return std::hash<typename _UP::pointer>()(__u.get()); diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index b74684228c1..d9c3b659e6b 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -818,7 +818,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Alloc> size_t hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>:: - operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const + operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const noexcept { size_t __hash = 0; using _GLIBCXX_STD_C::_S_word_bit; diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index 21d281787ad..f44bbcddefd 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -414,7 +414,7 @@ namespace __debug : public __hash_base<size_t, __debug::bitset<_Nb>> { size_t - operator()(const __debug::bitset<_Nb>& __b) const + operator()(const __debug::bitset<_Nb>& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); } }; #endif diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 82662b44605..5ee0fabc32a 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -625,7 +625,7 @@ namespace __debug : public __hash_base<size_t, __debug::vector<bool, _Alloc>> { size_t - operator()(const __debug::vector<bool, _Alloc>& __b) const + operator()(const __debug::vector<bool, _Alloc>& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>() (__b._M_base()); } }; diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index a613e364d3a..8c4120a3be2 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -2769,7 +2769,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, __gnu_cxx::__vstring> { size_t - operator()(const __gnu_cxx::__vstring& __s) const + operator()(const __gnu_cxx::__vstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length()); } }; @@ -2780,7 +2780,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, __gnu_cxx::__wvstring> { size_t - operator()(const __gnu_cxx::__wvstring& __s) const + operator()(const __gnu_cxx::__wvstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } }; @@ -2793,7 +2793,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, __gnu_cxx::__u16vstring> { size_t - operator()(const __gnu_cxx::__u16vstring& __s) const + operator()(const __gnu_cxx::__u16vstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char16_t)); } }; @@ -2804,7 +2804,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, __gnu_cxx::__u32vstring> { size_t - operator()(const __gnu_cxx::__u32vstring& __s) const + operator()(const __gnu_cxx::__u32vstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char32_t)); } }; diff --git a/libstdc++-v3/include/profile/bitset b/libstdc++-v3/include/profile/bitset index bd4aa3e152f..a2cba5efe80 100644 --- a/libstdc++-v3/include/profile/bitset +++ b/libstdc++-v3/include/profile/bitset @@ -372,7 +372,7 @@ namespace __profile : public __hash_base<size_t, __profile::bitset<_Nb>> { size_t - operator()(const __profile::bitset<_Nb>& __b) const + operator()(const __profile::bitset<_Nb>& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); } }; #endif diff --git a/libstdc++-v3/include/profile/vector b/libstdc++-v3/include/profile/vector index 86aefd649e3..0526c5aabb7 100644 --- a/libstdc++-v3/include/profile/vector +++ b/libstdc++-v3/include/profile/vector @@ -529,7 +529,7 @@ namespace __profile : public __hash_base<size_t, __profile::vector<bool, _Alloc>> { size_t - operator()(const __profile::vector<bool, _Alloc>& __b) const + operator()(const __profile::vector<bool, _Alloc>& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>() (__b._M_base()); } }; diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 813ed4b2599..e07c5e08970 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -1555,7 +1555,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>> { size_t - operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const + operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const noexcept { const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__; return std::_Hash_impl::hash(__b._M_getdata(), __clength); @@ -1567,7 +1567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>> { size_t - operator()(const _GLIBCXX_STD_C::bitset<0>&) const + operator()(const _GLIBCXX_STD_C::bitset<0>&) const noexcept { return 0; } }; diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 565261e709b..19482bc2181 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -361,7 +361,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, error_code> { size_t - operator()(const error_code& __e) const + operator()(const error_code& __e) const noexcept { const size_t __tmp = std::_Hash_impl::hash(__e._M_value); return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp); diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 8cc06903ebf..1d1733731bf 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -221,7 +221,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base<size_t, thread::id> { size_t - operator()(const thread::id& __id) const + operator()(const thread::id& __id) const noexcept { return std::_Hash_impl::hash(__id._M_thread); } }; diff --git a/libstdc++-v3/include/std/typeindex b/libstdc++-v3/include/std/typeindex index a92c2969b97..fa07ac620e6 100644 --- a/libstdc++-v3/include/std/typeindex +++ b/libstdc++-v3/include/std/typeindex @@ -76,7 +76,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !_M_target->before(*__rhs._M_target); } size_t - hash_code() const + hash_code() const noexcept { return _M_target->hash_code(); } const char* @@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef type_index argument_type; size_t - operator()(const type_index& __ti) const + operator()(const type_index& __ti) const noexcept { return __ti.hash_code(); } }; diff --git a/libstdc++-v3/libsupc++/typeinfo b/libstdc++-v3/libsupc++/typeinfo index 69311d69e9a..22ef49fa7b2 100644 --- a/libstdc++-v3/libsupc++/typeinfo +++ b/libstdc++-v3/libsupc++/typeinfo @@ -140,7 +140,7 @@ namespace std { return !operator==(__arg); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ - size_t hash_code() const throw() + size_t hash_code() const noexcept { # if !__GXX_MERGED_TYPEINFO_NAMES return _Hash_bytes(name(), __builtin_strlen(name()), diff --git a/libstdc++-v3/src/compatibility-ldbl.cc b/libstdc++-v3/src/compatibility-ldbl.cc index a9bdb8b0986..a103856adfa 100644 --- a/libstdc++-v3/src/compatibility-ldbl.cc +++ b/libstdc++-v3/src/compatibility-ldbl.cc @@ -1,6 +1,6 @@ // Compatibility symbols for -mlong-double-64 compatibility -*- C++ -*- -// Copyright (C) 2006, 2008, 2009, 2010 +// Copyright (C) 2006, 2008, 2009, 2010, 2011 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -69,14 +69,7 @@ namespace std _GLIBCXX_VISIBILITY(default) // For std::tr1::hash<long double>::operator() #define _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL - -namespace std _GLIBCXX_VISIBILITY(default) -{ - namespace tr1 - { -#include "hash-long-double-aux.cc" - } -} +#include "hash-long-double-tr1-aux.cc" // std::tr1::hash<long double>::operator() // and std::hash<long double>::operator() diff --git a/libstdc++-v3/src/hash-long-double-aux.cc b/libstdc++-v3/src/hash-long-double-aux.cc deleted file mode 100644 index d54d635f83e..00000000000 --- a/libstdc++-v3/src/hash-long-double-aux.cc +++ /dev/null @@ -1,50 +0,0 @@ -// std::hash and std::tr1::hash definitions, long double bits -*- C++ -*- - -// Copyright (C) 2010 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 even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// Under Section 7 of GPL version 3, you are granted additional -// permissions described in the GCC Runtime Library Exception, version -// 3.1, as published by the Free Software Foundation. - -// You should have received a copy of the GNU General Public License and -// a copy of the GCC Runtime Library Exception along with this program; -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -// <http://www.gnu.org/licenses/>. - - // For long double, careful with random padding bits (e.g., on x86, - // 10 bytes -> 12 bytes) and resort to frexp. - template<> - size_t - hash<long double>::operator()(long double __val) const - { - // 0 and -0 both hash to zero. - if (__val == 0.0L) - return 0; - - int __exponent; - __val = __builtin_frexpl(__val, &__exponent); - __val = __val < 0.0l ? -(__val + 0.5l) : __val; - - const long double __mult = __SIZE_MAX__ + 1.0l; - __val *= __mult; - - // Try to use all the bits of the mantissa (really necessary only - // on 32-bit targets, at least for 80-bit floating point formats). - const size_t __hibits = (size_t)__val; - __val = (__val - (long double)__hibits) * __mult; - - const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; - - return __hibits + (size_t)__val + __coeff * __exponent; - } diff --git a/libstdc++-v3/src/hash-long-double-tr1-aux.cc b/libstdc++-v3/src/hash-long-double-tr1-aux.cc new file mode 100644 index 00000000000..70ed45bbfbe --- /dev/null +++ b/libstdc++-v3/src/hash-long-double-tr1-aux.cc @@ -0,0 +1,56 @@ +// std::tr1::hash definitions, long double bits -*- C++ -*- + +// Copyright (C) 2010, 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 even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +namespace std _GLIBCXX_VISIBILITY(default) +{ + namespace tr1 + { + // For long double, careful with random padding bits (e.g., on x86, + // 10 bytes -> 12 bytes) and resort to frexp. + template<> + size_t + hash<long double>::operator()(long double __val) const + { + // 0 and -0 both hash to zero. + if (__val == 0.0L) + return 0; + + int __exponent; + __val = __builtin_frexpl(__val, &__exponent); + __val = __val < 0.0l ? -(__val + 0.5l) : __val; + + const long double __mult = __SIZE_MAX__ + 1.0l; + __val *= __mult; + + // Try to use all the bits of the mantissa (really necessary only + // on 32-bit targets, at least for 80-bit floating point formats). + const size_t __hibits = (size_t)__val; + __val = (__val - (long double)__hibits) * __mult; + + const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; + + return __hibits + (size_t)__val + __coeff * __exponent; + } + } +} diff --git a/libstdc++-v3/src/hash_c++0x.cc b/libstdc++-v3/src/hash_c++0x.cc index 852498df602..d685074540b 100644 --- a/libstdc++-v3/src/hash_c++0x.cc +++ b/libstdc++-v3/src/hash_c++0x.cc @@ -1,6 +1,6 @@ // std::hash definitions -*- C++ -*- -// Copyright (C) 2010 Free Software Foundation, Inc. +// Copyright (C) 2010, 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 @@ -30,5 +30,27 @@ namespace std _GLIBCXX_VISIBILITY(default) { -#include "hash-long-double-aux.cc" + _GLIBCXX_PURE size_t + hash<long double>::operator()(long double __val) const noexcept + { + // 0 and -0 both hash to zero. + if (__val == 0.0L) + return 0; + + int __exponent; + __val = __builtin_frexpl(__val, &__exponent); + __val = __val < 0.0l ? -(__val + 0.5l) : __val; + + const long double __mult = __SIZE_MAX__ + 1.0l; + __val *= __mult; + + // Try to use all the bits of the mantissa (really necessary only + // on 32-bit targets, at least for 80-bit floating point formats). + const size_t __hibits = (size_t)__val; + __val = (__val - (long double)__hibits) * __mult; + + const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; + + return __hibits + (size_t)__val + __coeff * __exponent; + } } diff --git a/libstdc++-v3/src/hash_tr1.cc b/libstdc++-v3/src/hash_tr1.cc index e707e827a11..a5ac87e585b 100644 --- a/libstdc++-v3/src/hash_tr1.cc +++ b/libstdc++-v3/src/hash_tr1.cc @@ -1,6 +1,6 @@ // std::tr1::hash definitions -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 2010, 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 @@ -25,12 +25,12 @@ #include <string> #include <tr1/functional> +#include "hash-long-double-tr1-aux.cc" + namespace std _GLIBCXX_VISIBILITY(default) { namespace tr1 { -#include "hash-long-double-aux.cc" - #ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL template<> size_t |