Changeset 80292


Ignore:
Timestamp:
Aug 28, 2012, 9:48:16 PM (6 years ago)
Author:
Daniel James
Message:

Hash: merge enum support + cleanup some tests.

Location:
branches/release
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/release

  • branches/release/boost

  • branches/release/boost/functional

  • branches/release/boost/functional/hash/hash.hpp

    r79544 r80292  
    1616#include <string>
    1717#include <boost/limits.hpp>
     18#include <boost/type_traits/is_enum.hpp>
     19#include <boost/utility/enable_if.hpp>
    1820
    1921#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
     
    9092    template <typename T>
    9193    typename boost::hash_detail::ulong_numbers<T>::type hash_value(T);
     94
     95    template <typename T>
     96    typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
     97        hash_value(T);
    9298
    9399#if !BOOST_WORKAROUND(__DMC__, <= 0x848)
     
    178184    {
    179185        return hash_detail::hash_value_unsigned(v);
     186    }
     187
     188    template <typename T>
     189    typename boost::enable_if<boost::is_enum<T>, std::size_t>::type
     190        hash_value(T v)
     191    {
     192        return static_cast<std::size_t>(v);
    180193    }
    181194
  • branches/release/libs

  • branches/release/libs/functional

  • branches/release/libs/functional/hash/test/Jamfile.v2

    r80286 r80292  
    2323        [ run hash_fwd_test_2.cpp ]
    2424        [ run hash_number_test.cpp ]
     25        [ run hash_enum_test.cpp ]
    2526        [ run hash_pointer_test.cpp ]
    2627        [ run hash_function_pointer_test.cpp ]
  • branches/release/libs/functional/hash/test/hash_enum_test.cpp

    r80139 r80292  
    1313
    1414#include <boost/detail/lightweight_test.hpp>
    15 
    16 #include <boost/mpl/assert.hpp>
    17 #include <boost/type_traits/is_base_and_derived.hpp>
     15#include "./compile_time.hpp"
    1816
    1917namespace test {
    2018        enum enum_override { enum_override1, enum_override2 };
    21         std::size_t hash_value(enum_override x) { return -896532; }
     19        std::size_t hash_value(enum_override) { return 896532; }
    2220
    2321        enum enum1 { enum1a };
     
    2826
    2927int main() {
    30         boost::hash<test::enum1> hash1;
    31         boost::hash<test::enum2> hash2;
    32         boost::hash<test::enum3> hash3;
    33         boost::hash<test::enum4> hash4;
     28        compile_time_tests((test::enum1*) 0);
     29        compile_time_tests((test::enum2*) 0);
     30        compile_time_tests((test::enum3*) 0);
     31        compile_time_tests((test::enum4*) 0);
     32        compile_time_tests((test::enum_override*) 0);
     33
     34        HASH_NAMESPACE::hash<test::enum1> hash1;
     35        HASH_NAMESPACE::hash<test::enum2> hash2;
     36        HASH_NAMESPACE::hash<test::enum3> hash3;
     37        HASH_NAMESPACE::hash<test::enum4> hash4;
    3438       
    3539        BOOST_TEST(hash1(test::enum1a) == hash1(test::enum1a));
     
    4751        BOOST_TEST(hash4(test::enum4b) == hash4(test::enum4b));
    4852
    49         boost::hash<test::enum_override> hash_override;
     53        HASH_NAMESPACE::hash<test::enum_override> hash_override;
    5054
    5155        BOOST_TEST(hash_override(test::enum_override1) ==
  • branches/release/libs/functional/hash/test/hash_function_pointer_test.cpp

    r53361 r80292  
    1313
    1414#include <boost/detail/lightweight_test.hpp>
    15 
    16 #include <boost/mpl/assert.hpp>
    17 #include <boost/type_traits/is_base_and_derived.hpp>
    18 
    1915#include "./compile_time.hpp"
    2016
  • branches/release/libs/functional/hash/test/hash_number_test.cpp

    r78319 r80292  
    1717#include <boost/preprocessor/cat.hpp>
    1818#include <boost/functional/hash/detail/limits.hpp>
    19 #include <boost/mpl/assert.hpp>
    20 #include <boost/type_traits/is_base_and_derived.hpp>
    2119
    2220#include "./compile_time.hpp"
  • branches/release/libs/functional/hash/test/hash_pointer_test.cpp

    r51729 r80292  
    1313
    1414#include <boost/detail/lightweight_test.hpp>
    15 
    1615#include <boost/limits.hpp>
    17 #include <boost/mpl/assert.hpp>
    18 #include <boost/type_traits/is_base_and_derived.hpp>
    19 
    2016#include "./compile_time.hpp"
    2117
  • branches/release/libs/functional/hash/test/hash_range_test.cpp

    r58801 r80292  
    1919
    2020#include <boost/detail/lightweight_test.hpp>
    21 
    2221#include <boost/limits.hpp>
    23 #include <boost/mpl/assert.hpp>
    24 #include <boost/type_traits/is_base_and_derived.hpp>
    2522#include <vector>
    2623
  • branches/release/libs/functional/hash/test/hash_string_test.cpp

    r53361 r80292  
    1313
    1414#include <boost/detail/lightweight_test.hpp>
    15 
    16 #include <boost/mpl/assert.hpp>
    17 #include <boost/type_traits/is_base_and_derived.hpp>
    1815#include <string>
    19 
    2016#include "./compile_time.hpp"
    2117
Note: See TracChangeset for help on using the changeset viewer.