Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80292 - in branches/release: . boost boost/functional boost/functional/hash libs libs/functional libs/functional/hash/test
From: dnljms_at_[hidden]
Date: 2012-08-28 17:48:17


Author: danieljames
Date: 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
New Revision: 80292
URL: http://svn.boost.org/trac/boost/changeset/80292

Log:
Hash: merge enum support + cleanup some tests.

Added:
   branches/release/libs/functional/hash/test/hash_enum_test.cpp
      - copied, changed from r80139, /trunk/libs/functional/hash/test/hash_enum_test.cpp
Properties modified:
   branches/release/ (props changed)
   branches/release/boost/ (props changed)
   branches/release/boost/functional/ (props changed)
   branches/release/libs/ (props changed)
   branches/release/libs/functional/ (props changed)
Text files modified:
   branches/release/boost/functional/hash/hash.hpp | 13 +++++++++++++
   branches/release/libs/functional/hash/test/Jamfile.v2 | 1 +
   branches/release/libs/functional/hash/test/hash_enum_test.cpp | 22 +++++++++++++---------
   branches/release/libs/functional/hash/test/hash_function_pointer_test.cpp | 4 ----
   branches/release/libs/functional/hash/test/hash_number_test.cpp | 2 --
   branches/release/libs/functional/hash/test/hash_pointer_test.cpp | 4 ----
   branches/release/libs/functional/hash/test/hash_range_test.cpp | 3 ---
   branches/release/libs/functional/hash/test/hash_string_test.cpp | 4 ----
   8 files changed, 27 insertions(+), 26 deletions(-)

Modified: branches/release/boost/functional/hash/hash.hpp
==============================================================================
--- branches/release/boost/functional/hash/hash.hpp (original)
+++ branches/release/boost/functional/hash/hash.hpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -15,6 +15,8 @@
 #include <boost/functional/hash/detail/hash_float.hpp>
 #include <string>
 #include <boost/limits.hpp>
+#include <boost/type_traits/is_enum.hpp>
+#include <boost/utility/enable_if.hpp>
 
 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 #include <boost/type_traits/is_pointer.hpp>
@@ -90,6 +92,10 @@
     template <typename T>
     typename boost::hash_detail::ulong_numbers<T>::type hash_value(T);
 
+ template <typename T>
+ typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
+ hash_value(T);
+
 #if !BOOST_WORKAROUND(__DMC__, <= 0x848)
     template <class T> std::size_t hash_value(T* const&);
 #else
@@ -179,6 +185,13 @@
         return hash_detail::hash_value_unsigned(v);
     }
 
+ template <typename T>
+ typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
+ hash_value(T v)
+ {
+ return static_cast<std::size_t>(v);
+ }
+
     // Implementation by Alberto Barbati and Dave Harris.
 #if !BOOST_WORKAROUND(__DMC__, <= 0x848)
     template <class T> std::size_t hash_value(T* const& v)

Modified: branches/release/libs/functional/hash/test/Jamfile.v2
==============================================================================
--- branches/release/libs/functional/hash/test/Jamfile.v2 (original)
+++ branches/release/libs/functional/hash/test/Jamfile.v2 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -22,6 +22,7 @@
         [ run hash_fwd_test_1.cpp ]
         [ run hash_fwd_test_2.cpp ]
         [ run hash_number_test.cpp ]
+ [ run hash_enum_test.cpp ]
         [ run hash_pointer_test.cpp ]
         [ run hash_function_pointer_test.cpp ]
         [ run hash_float_test.cpp ]

Copied: branches/release/libs/functional/hash/test/hash_enum_test.cpp (from r80139, /trunk/libs/functional/hash/test/hash_enum_test.cpp)
==============================================================================
--- /trunk/libs/functional/hash/test/hash_enum_test.cpp (original)
+++ branches/release/libs/functional/hash/test/hash_enum_test.cpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -12,13 +12,11 @@
 #endif
 
 #include <boost/detail/lightweight_test.hpp>
-
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
+#include "./compile_time.hpp"
 
 namespace test {
         enum enum_override { enum_override1, enum_override2 };
- std::size_t hash_value(enum_override x) { return -896532; }
+ std::size_t hash_value(enum_override) { return 896532; }
 
         enum enum1 { enum1a };
         enum enum2 { enum2a, enum2b };
@@ -27,10 +25,16 @@
 }
 
 int main() {
- boost::hash<test::enum1> hash1;
- boost::hash<test::enum2> hash2;
- boost::hash<test::enum3> hash3;
- boost::hash<test::enum4> hash4;
+ compile_time_tests((test::enum1*) 0);
+ compile_time_tests((test::enum2*) 0);
+ compile_time_tests((test::enum3*) 0);
+ compile_time_tests((test::enum4*) 0);
+ compile_time_tests((test::enum_override*) 0);
+
+ HASH_NAMESPACE::hash<test::enum1> hash1;
+ HASH_NAMESPACE::hash<test::enum2> hash2;
+ HASH_NAMESPACE::hash<test::enum3> hash3;
+ HASH_NAMESPACE::hash<test::enum4> hash4;
         
         BOOST_TEST(hash1(test::enum1a) == hash1(test::enum1a));
 
@@ -46,7 +50,7 @@
         BOOST_TEST(hash4(test::enum4a) != hash4(test::enum4b));
         BOOST_TEST(hash4(test::enum4b) == hash4(test::enum4b));
 
- boost::hash<test::enum_override> hash_override;
+ HASH_NAMESPACE::hash<test::enum_override> hash_override;
 
         BOOST_TEST(hash_override(test::enum_override1) ==
                 hash_override(test::enum_override1));

Modified: branches/release/libs/functional/hash/test/hash_function_pointer_test.cpp
==============================================================================
--- branches/release/libs/functional/hash/test/hash_function_pointer_test.cpp (original)
+++ branches/release/libs/functional/hash/test/hash_function_pointer_test.cpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -12,10 +12,6 @@
 #endif
 
 #include <boost/detail/lightweight_test.hpp>
-
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
-
 #include "./compile_time.hpp"
 
 void void_func1() { static int x = 1; ++x; }

Modified: branches/release/libs/functional/hash/test/hash_number_test.cpp
==============================================================================
--- branches/release/libs/functional/hash/test/hash_number_test.cpp (original)
+++ branches/release/libs/functional/hash/test/hash_number_test.cpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -16,8 +16,6 @@
 
 #include <boost/preprocessor/cat.hpp>
 #include <boost/functional/hash/detail/limits.hpp>
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
 
 #include "./compile_time.hpp"
 

Modified: branches/release/libs/functional/hash/test/hash_pointer_test.cpp
==============================================================================
--- branches/release/libs/functional/hash/test/hash_pointer_test.cpp (original)
+++ branches/release/libs/functional/hash/test/hash_pointer_test.cpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -12,11 +12,7 @@
 #endif
 
 #include <boost/detail/lightweight_test.hpp>
-
 #include <boost/limits.hpp>
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
-
 #include "./compile_time.hpp"
 
 void pointer_tests()

Modified: branches/release/libs/functional/hash/test/hash_range_test.cpp
==============================================================================
--- branches/release/libs/functional/hash/test/hash_range_test.cpp (original)
+++ branches/release/libs/functional/hash/test/hash_range_test.cpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -18,10 +18,7 @@
 #endif
 
 #include <boost/detail/lightweight_test.hpp>
-
 #include <boost/limits.hpp>
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
 #include <vector>
 
 void hash_range_tests()

Modified: branches/release/libs/functional/hash/test/hash_string_test.cpp
==============================================================================
--- branches/release/libs/functional/hash/test/hash_string_test.cpp (original)
+++ branches/release/libs/functional/hash/test/hash_string_test.cpp 2012-08-28 17:48:16 EDT (Tue, 28 Aug 2012)
@@ -12,11 +12,7 @@
 #endif
 
 #include <boost/detail/lightweight_test.hpp>
-
-#include <boost/mpl/assert.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
 #include <string>
-
 #include "./compile_time.hpp"
 
 void string_tests()


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk