hashable.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*!
  2. @file
  3. Forward declares `boost::hana::Hashable`.
  4. @copyright Louis Dionne 2016
  5. @copyright Jason Rice 2016
  6. Distributed under the Boost Software License, Version 1.0.
  7. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  8. */
  9. #ifndef BOOST_HANA_FWD_CONCEPT_HASHABLE_HPP
  10. #define BOOST_HANA_FWD_CONCEPT_HASHABLE_HPP
  11. #include <boost/hana/config.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! @ingroup group-concepts
  14. //! @defgroup group-Hashable Hashable
  15. //! The `Hashable` concept represents objects that can be normalized to
  16. //! a type-level hash.
  17. //!
  18. //! In day to day programming, hashes are very important as a way to
  19. //! efficiently lookup objects in maps. While the implementation of
  20. //! maps is very different, the same idea of using hashes for efficient
  21. //! lookup applies in metaprogramming. The `Hashable` concept represents
  22. //! objects that can be summarized (possibly with loss of information) to
  23. //! a type, in a way suitable for use in hash-based data structures. Of
  24. //! course, in order for a hash to be well-behaved, it must obey some laws
  25. //! that are explained below.
  26. //!
  27. //!
  28. //! Minimal complete definition
  29. //! ---------------------------
  30. //! `hash`, satisfying the laws below
  31. //!
  32. //!
  33. //! Laws
  34. //! ----
  35. //! First, `hana::hash` must return a `hana::type`. Furthermore, for any
  36. //! two `Hashable` objects `x` and `y`, it must be the case that
  37. //! @code
  38. //! x == y implies hash(x) == hash(y)
  39. //! @endcode
  40. //!
  41. //! where `==` denotes `hana::equal`. In other words, any two objects that
  42. //! compare equal (with `hana::equal`) must also have the same hash.
  43. //! However, the reverse is not true, and two different objects may have
  44. //! the same hash. This situation of two different objects having the same
  45. //! hash is called a _collision_.
  46. //!
  47. //!
  48. //! Concrete models
  49. //! ---------------
  50. //! `hana::integral_constant`, `hana::type`, `hana::string`
  51. //!
  52. //!
  53. //! Free model for `IntegralConstant`s
  54. //! ----------------------------------
  55. //! Any `IntegralConstant` is `Hashable`, by normalizing its value to a
  56. //! `hana::integral_constant`. The type of the value held in the normalized
  57. //! `integral_constant` is `unsigned long long` for unsigned integral
  58. //! types, and `signed long long` for signed integral types.
  59. template <typename T>
  60. struct Hashable;
  61. BOOST_HANA_NAMESPACE_END
  62. #endif // !BOOST_HANA_FWD_CONCEPT_HASHABLE_HPP