mirror of
https://github.com/boostorg/functional.git
synced 2025-08-02 05:54:29 +02:00
Hash: std::shared_ptr
, std::unique_ptr
support.
[SVN r79516]
This commit is contained in:
@@ -42,6 +42,7 @@ test-suite functional/hash
|
|||||||
[ run hash_type_index_test.cpp ]
|
[ run hash_type_index_test.cpp ]
|
||||||
[ run hash_std_array_test.cpp ]
|
[ run hash_std_array_test.cpp ]
|
||||||
[ run hash_std_tuple_test.cpp ]
|
[ run hash_std_tuple_test.cpp ]
|
||||||
|
[ run hash_std_smart_ptr_test.cpp ]
|
||||||
[ run link_test.cpp link_test_2.cpp ]
|
[ run link_test.cpp link_test_2.cpp ]
|
||||||
[ run link_ext_test.cpp link_no_ext_test.cpp ]
|
[ run link_ext_test.cpp link_no_ext_test.cpp ]
|
||||||
[ run extensions_hpp_test.cpp ]
|
[ run extensions_hpp_test.cpp ]
|
||||||
|
80
hash/test/hash_std_smart_ptr_test.cpp
Normal file
80
hash/test/hash_std_smart_ptr_test.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
// Copyright 2012 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 "./config.hpp"
|
||||||
|
|
||||||
|
#ifdef TEST_STD_INCLUDES
|
||||||
|
# include <functional>
|
||||||
|
#else
|
||||||
|
# include <boost/functional/hash.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include "./compile_time.hpp"
|
||||||
|
|
||||||
|
#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||||
|
#define TEST_SMART_PTRS
|
||||||
|
#include <memory>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TEST_SMART_PTRS
|
||||||
|
|
||||||
|
void shared_ptr_tests()
|
||||||
|
{
|
||||||
|
std::shared_ptr<int> x;
|
||||||
|
compile_time_tests(&x);
|
||||||
|
|
||||||
|
HASH_NAMESPACE::hash<std::shared_ptr<int> > x1;
|
||||||
|
HASH_NAMESPACE::hash<std::shared_ptr<int> > x2;
|
||||||
|
|
||||||
|
std::shared_ptr<int> ptr1(new int(10));
|
||||||
|
std::shared_ptr<int> ptr2;
|
||||||
|
|
||||||
|
BOOST_TEST(x1(x) == x2(ptr2));
|
||||||
|
BOOST_TEST(x1(x) != x2(ptr1));
|
||||||
|
ptr2.reset(new int(10));
|
||||||
|
BOOST_TEST(x1(ptr1) == x2(ptr1));
|
||||||
|
BOOST_TEST(x1(ptr1) != x2(ptr2));
|
||||||
|
ptr2 = ptr1;
|
||||||
|
BOOST_TEST(x1(ptr1) == x2(ptr2));
|
||||||
|
#if defined(TEST_EXTENSIONS)
|
||||||
|
BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x));
|
||||||
|
BOOST_TEST(x1(ptr1) == HASH_NAMESPACE::hash_value(ptr2));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void unique_ptr_tests()
|
||||||
|
{
|
||||||
|
std::unique_ptr<int> x;
|
||||||
|
compile_time_tests(&x);
|
||||||
|
|
||||||
|
HASH_NAMESPACE::hash<std::unique_ptr<int> > x1;
|
||||||
|
HASH_NAMESPACE::hash<std::unique_ptr<int> > x2;
|
||||||
|
|
||||||
|
std::unique_ptr<int> ptr1(new int(10));
|
||||||
|
std::unique_ptr<int> ptr2;
|
||||||
|
|
||||||
|
BOOST_TEST(x1(x) == x2(ptr2));
|
||||||
|
BOOST_TEST(x1(x) != x2(ptr1));
|
||||||
|
ptr2.reset(new int(10));
|
||||||
|
BOOST_TEST(x1(ptr1) == x2(ptr1));
|
||||||
|
BOOST_TEST(x1(ptr1) != x2(ptr2));
|
||||||
|
|
||||||
|
#if defined(TEST_EXTENSIONS)
|
||||||
|
BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#ifdef TEST_SMART_PTRS
|
||||||
|
shared_ptr_tests();
|
||||||
|
unique_ptr_tests();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
@@ -38,4 +38,18 @@ namespace std {
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// std::shared_ptr/std::unique_ptr
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_HDR_MEMORY)
|
||||||
|
# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \
|
||||||
|
!defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD))
|
||||||
|
# include <memory>
|
||||||
|
# else
|
||||||
|
namespace std {
|
||||||
|
template <class> class shared_ptr;
|
||||||
|
template <class, class> class unique_ptr;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -177,6 +177,18 @@ namespace boost
|
|||||||
# undef BOOST_HASH_TUPLE_F
|
# undef BOOST_HASH_TUPLE_F
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_HDR_MEMORY)
|
||||||
|
template <typename T>
|
||||||
|
inline std::size_t hash_value(std::shared_ptr<T> const& x) {
|
||||||
|
return boost::hash_value(x.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename Deleter>
|
||||||
|
inline std::size_t hash_value(std::unique_ptr<T, Deleter> const& x) {
|
||||||
|
return boost::hash_value(x.get());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user