File: test_hash.cpp

package info (click to toggle)
boost 1.34.1-14
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 116,412 kB
  • ctags: 259,566
  • sloc: cpp: 642,395; xml: 56,450; python: 17,612; ansic: 14,520; sh: 2,265; yacc: 858; perl: 481; makefile: 478; lex: 94; sql: 74; csh: 6
file content (60 lines) | stat: -rw-r--r-- 1,802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//  (C) Copyright John Maddock 2005.
//  Use, modification and distribution are subject to 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)

#ifdef TEST_STD_HEADERS
#include <functional>
#else
#include <boost/tr1/functional.hpp>
#endif

#include <string>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include "verify_return.hpp"

template <class T>
void check_hash(T t)
{
   typedef std::tr1::hash<T> hash_type;
   typedef typename hash_type::argument_type arg_type;
   typedef typename hash_type::result_type result_type;
   BOOST_STATIC_ASSERT((::boost::is_same<result_type, std::size_t>::value));
   BOOST_STATIC_ASSERT((::boost::is_same<arg_type, T>::value));
   BOOST_STATIC_ASSERT((::boost::is_base_of<std::unary_function<arg_type, result_type>, hash_type>::value));

   hash_type h;
   const hash_type& ch = h;

   verify_return_type(ch(t), std::size_t(0));
}

class UDT;

int main()
{
   check_hash(0);
   check_hash(0u);
   check_hash(0L);
   check_hash(0uL);
   check_hash(static_cast<short>(0));
   check_hash(static_cast<unsigned short>(0));
   check_hash(static_cast<signed char>(0));
   check_hash(static_cast<unsigned char>(0));
   check_hash(static_cast<char>(0));
   check_hash(static_cast<wchar_t>(0));
   check_hash(static_cast<bool>(0));
   check_hash(static_cast<float>(0));
   check_hash(static_cast<double>(0));
   check_hash(static_cast<long double>(0));
   check_hash(std::string(""));
   check_hash(std::wstring(L""));
   check_hash(static_cast<UDT*>(0));
   check_hash(static_cast<const UDT*>(0));
   check_hash(static_cast<volatile UDT*>(0));
   check_hash(static_cast<const volatile UDT*>(0));
   return 0;
}