diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-02-23 15:23:37 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-02-23 15:23:37 +0000 |
commit | 3103d73cdcd9f75c792c1213d242371410ea4fb7 (patch) | |
tree | 5a389c42914e410ce5375c1480147999b90aeb07 /libstdc++-v3/include/tr1 | |
parent | d96f9313aeb7cc7816eb9abfabb5ee1dcd5499ef (diff) | |
download | ppe42-gcc-3103d73cdcd9f75c792c1213d242371410ea4fb7.tar.gz ppe42-gcc-3103d73cdcd9f75c792c1213d242371410ea4fb7.zip |
2010-02-23 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/functional_hash.h (struct _Fnv_hash): Rename
to _Fnv_hash_base.
(struct _Fnv_hash): Add, derives from the latter.
(__hash_combine): Add.
(hash<float>::operator()(float), hash<double>::operator()(double)):
Adjust.
* include/bits/basic_string.h (hash<string>, hash<wstring>,
hash<u16string>, hash<u32string>): Adjust.
* src/hash-string-aux.cc: Adjust.
* src/compatibility-c++0x.cc (hash<error_code>): Use __hash_combine.
* include/std/system_error (hash<error_code>): Likewise.
* include/std/thread (struct hash<thread::id>): Add.
* include/tr1/functional_hash.h : Rename to _Fnv_hash_base.
(struct _Fnv_hash): Add, derives from the latter.
(hash<float>::operator()(float), hash<double>::operator()(double)):
Adjust.
* testsuite/30_threads/thread/id/hash.cc: New.
* testsuite/30_threads/thread/cons/assign_neg.cc: Adjust dg-error
line number.
* testsuite/30_threads/thread/cons/copy_neg.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157005 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/tr1')
-rw-r--r-- | libstdc++-v3/include/tr1/functional_hash.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/libstdc++-v3/include/tr1/functional_hash.h b/libstdc++-v3/include/tr1/functional_hash.h index d944fa9ff0f..98fb1878695 100644 --- a/libstdc++-v3/include/tr1/functional_hash.h +++ b/libstdc++-v3/include/tr1/functional_hash.h @@ -1,6 +1,6 @@ // TR1 functional_hash.h header -*- C++ -*- -// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 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 @@ -82,8 +82,8 @@ namespace tr1 // (Used by the next specializations of std::tr1::hash.) /// Dummy generic implementation (for sizeof(size_t) != 4, 8). - template<size_t = sizeof(size_t)> - struct _Fnv_hash + template<size_t> + struct _Fnv_hash_base { static size_t hash(const char* __first, size_t __length) @@ -96,7 +96,7 @@ namespace tr1 }; template<> - struct _Fnv_hash<4> + struct _Fnv_hash_base<4> { static size_t hash(const char* __first, size_t __length) @@ -112,7 +112,7 @@ namespace tr1 }; template<> - struct _Fnv_hash<8> + struct _Fnv_hash_base<8> { static size_t hash(const char* __first, size_t __length) @@ -128,18 +128,25 @@ namespace tr1 } }; + struct _Fnv_hash + : public _Fnv_hash_base<sizeof(size_t)> + { + using _Fnv_hash_base<sizeof(size_t)>::hash; + + template<typename _Tp> + static size_t + hash(const _Tp& __val) + { return hash(reinterpret_cast<const char*>(&__val), + sizeof(__val)); } + }; + /// Explicit specializations for float. template<> inline size_t hash<float>::operator()(float __val) const { - size_t __result = 0; - // 0 and -0 both hash to zero. - if (__val != 0.0f) - __result = _Fnv_hash<>::hash(reinterpret_cast<const char*>(&__val), - sizeof(__val)); - return __result; + return __val != 0.0f ? std::tr1::_Fnv_hash::hash(__val) : 0; } /// Explicit specializations for double. @@ -147,13 +154,8 @@ namespace tr1 inline size_t hash<double>::operator()(double __val) const { - size_t __result = 0; - - // 0 and -0 both hash to zero. - if (__val != 0.0) - __result = _Fnv_hash<>::hash(reinterpret_cast<const char*>(&__val), - sizeof(__val)); - return __result; + // 0 and -0 both hash to zero. + return __val != 0.0 ? std::tr1::_Fnv_hash::hash(__val) : 0; } /// Explicit specializations for long double. |