mirror of
https://github.com/boostorg/functional.git
synced 2025-08-02 22:14:28 +02:00
Merge iostreams, hash.
Including disallowing implicit casts to `hash_value`. [SVN r63812]
This commit is contained in:
@@ -106,4 +106,12 @@
|
||||
Avoid hashing 0.5 and 0 to the same number.
|
||||
* Stop using deprecated `BOOST_HAS_*` macros.
|
||||
|
||||
[h2 Boost 1.44.0]
|
||||
|
||||
* Prevent implicit conversions when calling `hash_value`. If you find
|
||||
that the new version breaks your code, you can enable the old
|
||||
behaviour by defining `BOOST_HASH_ALLOW_IMPLICIT_CASTS` - although
|
||||
I would recommend that you update your code to work with the new
|
||||
version.
|
||||
|
||||
[endsect]
|
||||
|
@@ -50,6 +50,8 @@ test-suite functional/hash
|
||||
[ run container_no_fwd_test.cpp ]
|
||||
[ compile-fail hash_no_ext_fail_test.cpp ]
|
||||
[ compile-fail namespace_fail_test.cpp ]
|
||||
[ compile-fail implicit_fail_test.cpp ]
|
||||
[ compile-fail shared_ptr_fail_test.cpp ]
|
||||
[ run hash_no_ext_macro_1.cpp ]
|
||||
[ run hash_no_ext_macro_2.cpp ]
|
||||
;
|
||||
|
21
hash/test/implicit_fail_test.cpp
Normal file
21
hash/test/implicit_fail_test.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
// Copyright 2010 Daniel James.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
namespace test
|
||||
{
|
||||
struct base {};
|
||||
std::size_t hash_value(base const&) { return 0; }
|
||||
|
||||
struct converts { operator base() const { return base(); } };
|
||||
}
|
||||
|
||||
int main() {
|
||||
boost::hash<test::converts> hash;
|
||||
test::converts x;
|
||||
|
||||
hash(x);
|
||||
}
|
16
hash/test/shared_ptr_fail_test.cpp
Normal file
16
hash/test/shared_ptr_fail_test.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
// Copyright 2010 Daniel James.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// This should obviously pass if shared_ptr ever supports Boost.Hash.
|
||||
|
||||
int main() {
|
||||
boost::hash<boost::shared_ptr<int> > hash;
|
||||
boost::shared_ptr<int> x(new int(10));
|
||||
|
||||
hash(x);
|
||||
}
|
@@ -15,6 +15,7 @@
|
||||
#include <boost/functional/hash/detail/hash_float.hpp>
|
||||
#include <string>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
#include <boost/type_traits/is_pointer.hpp>
|
||||
@@ -29,6 +30,18 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
#if !defined(BOOST_HASH_ALLOW_IMPLICIT_CASTS)
|
||||
|
||||
// If you get a static assertion here, it's because hash_value
|
||||
// isn't declared for your type.
|
||||
template <typename T>
|
||||
std::size_t hash_value(T const&) {
|
||||
BOOST_STATIC_ASSERT((T*) 0 && false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::size_t hash_value(bool);
|
||||
std::size_t hash_value(char);
|
||||
std::size_t hash_value(unsigned char);
|
||||
|
Reference in New Issue
Block a user