|
|
|||
File indexing completed on 2025-12-15 09:53:04
0001 /*! 0002 @file 0003 Forward declares `boost::hana::hash`. 0004 0005 Copyright Louis Dionne 2016 0006 Copyright Jason Rice 2016 0007 Distributed under the Boost Software License, Version 1.0. 0008 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0009 */ 0010 0011 #ifndef BOOST_HANA_FWD_HASH_HPP 0012 #define BOOST_HANA_FWD_HASH_HPP 0013 0014 #include <boost/hana/config.hpp> 0015 #include <boost/hana/core/when.hpp> 0016 0017 0018 namespace boost { namespace hana { 0019 //! Returns a `hana::type` representing the compile-time hash of an object. 0020 //! @ingroup group-Hashable 0021 //! 0022 //! Given an arbitrary object `x`, `hana::hash` returns a `hana::type` 0023 //! representing the hash of `x`. In normal programming, hashes are 0024 //! usually numerical values that can be used e.g. as indices in an 0025 //! array as part of the implementation of a hash table. In the context 0026 //! of metaprogramming, we are interested in type-level hashes instead. 0027 //! Thus, `hana::hash` must return a `hana::type` object instead of an 0028 //! integer. This `hana::type` must somehow summarize the object being 0029 //! hashed, but that summary may of course lose some information. 0030 //! 0031 //! In order for the `hash` function to be defined properly, it must be 0032 //! the case that whenever `x` is equal to `y`, then `hash(x)` is equal 0033 //! to `hash(y)`. This ensures that `hana::hash` is a function in the 0034 //! mathematical sense of the term. 0035 //! 0036 //! 0037 //! Signature 0038 //! --------- 0039 //! Given a `Hashable` `H`, the signature is 0040 //! \f$ 0041 //! \mathtt{hash} : H \to \mathtt{type\_tag} 0042 //! \f$ 0043 //! 0044 //! @param x 0045 //! An object whose hash is to be computed. 0046 //! 0047 //! 0048 //! Example 0049 //! ------- 0050 //! @include example/hash.cpp 0051 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0052 constexpr auto hash = [](auto const& x) { 0053 return tag-dispatched; 0054 }; 0055 #else 0056 template <typename T, typename = void> 0057 struct hash_impl : hash_impl<T, when<true>> { }; 0058 0059 struct hash_t { 0060 template <typename X> 0061 constexpr auto operator()(X const& x) const; 0062 }; 0063 0064 BOOST_HANA_INLINE_VARIABLE constexpr hash_t hash{}; 0065 #endif 0066 }} // end namespace boost::hana 0067 0068 #endif // !BOOST_HANA_FWD_HASH_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|