]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/functional/hash/examples/portable.cpp
2 // Copyright 2005-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // Force use of assert.
11 #include <boost/functional/hash.hpp>
14 // This example illustrates how to customise boost::hash portably, so that
15 // it'll work on both compilers that don't implement argument dependent lookup
16 // and compilers that implement strict two-phase template instantiation.
25 custom_type(T x
) : value(x
) {}
27 std::size_t hash() const
29 boost::hash
<T
> hasher
;
35 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
42 std::size_t hash_value(foo::custom_type
<T
> x
)
50 foo::custom_type
<int> x(1), y(2), z(1);
52 boost::hash
<foo::custom_type
<int> > hasher
;
54 assert(hasher(x
) == hasher(x
));
55 assert(hasher(x
) != hasher(y
));
56 assert(hasher(x
) == hasher(z
));