]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/fwd/hash.hpp
38602db518b63257b758a47f8c095acc379a306b
[ceph.git] / ceph / src / boost / boost / hana / fwd / hash.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::hash`.
4
5 @copyright Louis Dionne 2016
6 @copyright Jason Rice 2016
7 Distributed under the Boost Software License, Version 1.0.
8 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
9 */
10
11 #ifndef BOOST_HANA_FWD_HASH_HPP
12 #define BOOST_HANA_FWD_HASH_HPP
13
14 #include <boost/hana/config.hpp>
15 #include <boost/hana/core/when.hpp>
16
17
18 BOOST_HANA_NAMESPACE_BEGIN
19 //! Returns a `hana::type` representing the compile-time hash of an object.
20 //! @ingroup group-Hashable
21 //!
22 //! Given an arbitrary object `x`, `hana::hash` returns a `hana::type`
23 //! representing the hash of `x`. In normal programming, hashes are
24 //! usually numerical values that can be used e.g. as indices in an
25 //! array as part of the implementation of a hash table. In the context
26 //! of metaprogramming, we are interested in type-level hashes instead.
27 //! Thus, `hana::hash` must return a `hana::type` object instead of an
28 //! integer. This `hana::type` must somehow summarize the object being
29 //! hashed, but that summary may of course lose some information.
30 //!
31 //! In order for the `hash` function to be defined properly, it must be
32 //! the case that whenever `x` is equal to `y`, then `hash(x)` is equal
33 //! to `hash(y)`. This ensures that `hana::hash` is a function in the
34 //! mathematical sense of the term.
35 //!
36 //!
37 //! Signature
38 //! ---------
39 //! Given a `Hashable` `H`, the signature is
40 //! \f$
41 //! \mathtt{hash} : H \to \mathtt{type\_tag}
42 //! \f$
43 //!
44 //! @param x
45 //! An object whose hash is to be computed.
46 //!
47 //!
48 //! Example
49 //! -------
50 //! @include example/hash.cpp
51 #ifdef BOOST_HANA_DOXYGEN_INVOKED
52 constexpr auto hash = [](auto const& x) {
53 return tag-dispatched;
54 };
55 #else
56 template <typename T, typename = void>
57 struct hash_impl : hash_impl<T, when<true>> { };
58
59 struct hash_t {
60 template <typename X>
61 constexpr auto operator()(X const& x) const;
62 };
63
64 constexpr hash_t hash{};
65 #endif
66 BOOST_HANA_NAMESPACE_END
67
68 #endif // !BOOST_HANA_FWD_HASH_HPP