]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/tr1/test/test_hash.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / tr1 / test / test_hash.cpp
CommitLineData
7c673cae
FG
1// (C) Copyright John Maddock 2005.
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifdef TEST_STD_HEADERS
7#include <functional>
8#else
9#include <boost/tr1/functional.hpp>
10#endif
11
12#include <string>
13#include <boost/static_assert.hpp>
14#include <boost/type_traits/is_same.hpp>
15#include <boost/type_traits/is_base_of.hpp>
16#include "verify_return.hpp"
17
18template <class T>
19void check_hash(T t)
20{
21 typedef std::tr1::hash<T> hash_type;
22 typedef typename hash_type::argument_type arg_type;
23 typedef typename hash_type::result_type result_type;
24 BOOST_STATIC_ASSERT((::boost::is_same<result_type, std::size_t>::value));
25 BOOST_STATIC_ASSERT((::boost::is_same<arg_type, T>::value));
26 BOOST_STATIC_ASSERT((::boost::is_base_of<std::unary_function<arg_type, result_type>, hash_type>::value));
27
28 hash_type h;
29 const hash_type& ch = h;
30
31 verify_return_type(ch(t), std::size_t(0));
32}
33
34class UDT
35{
36 int m_value;
37public:
38 UDT(int v) : m_value(v) {}
39 int value()const { return m_value; }
40};
41
42namespace std{ namespace tr1{
43
44template<>
45struct hash<UDT> : public std::unary_function<UDT, std::size_t>
46{
47 typedef UDT argument_type;
48 typedef std::size_t result_type;
49 std::size_t operator()(const UDT& u)const
50 {
51 std::tr1::hash<int> h;
52 return h(u.value());
53 }
54};
55
56}}
57
58int main()
59{
60 check_hash(0);
61 check_hash(0u);
62 check_hash(0L);
63 check_hash(0uL);
64 check_hash(static_cast<short>(0));
65 check_hash(static_cast<unsigned short>(0));
66 check_hash(static_cast<signed char>(0));
67 check_hash(static_cast<unsigned char>(0));
68 check_hash(static_cast<char>(0));
69 check_hash(static_cast<wchar_t>(0));
70 check_hash(static_cast<bool>(0));
71 check_hash(static_cast<float>(0));
72 check_hash(static_cast<double>(0));
73 check_hash(static_cast<long double>(0));
74 check_hash(std::string(""));
75 check_hash(std::wstring(L""));
76 check_hash(static_cast<UDT*>(0));
77 check_hash(static_cast<const UDT*>(0));
78 check_hash(static_cast<volatile UDT*>(0));
79 check_hash(static_cast<const volatile UDT*>(0));
80 check_hash(UDT(1));
81 return 0;
82}
83