integral_constant.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*!
  2. @file
  3. Forward declares `boost::hana::IntegralConstant`.
  4. Copyright Louis Dionne 2013-2022
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_FWD_CONCEPT_INTEGRAL_CONSTANT_HPP
  9. #define BOOST_HANA_FWD_CONCEPT_INTEGRAL_CONSTANT_HPP
  10. #include <boost/hana/config.hpp>
  11. namespace boost { namespace hana {
  12. //! @ingroup group-concepts
  13. //! The `IntegralConstant` concept represents compile-time integral values.
  14. //!
  15. //! The `IntegralConstant` concept represents objects that hold a
  16. //! `constexpr` value of an integral type. In other words, it describes
  17. //! the essential functionality provided by `std::integral_constant`.
  18. //! An `IntegralConstant` is also just a special kind of `Constant`
  19. //! whose inner value is of an integral type.
  20. //!
  21. //!
  22. //! Minimal complete definition
  23. //! ---------------------------
  24. //! The requirements for being an `IntegralConstant` are quite simple.
  25. //! First, an `IntegralConstant` `C` must be a `Constant` such that
  26. //! `Tag::value_type` is an integral type, where `Tag` is the tag of `C`.
  27. //!
  28. //! Secondly, `C` must have a nested `static constexpr` member named
  29. //! `value`, such that the following code is valid:
  30. //! @code
  31. //! constexpr auto v = C::value;
  32. //! @endcode
  33. //! Because of the requirement that `Tag::value_type` be an integral type,
  34. //! it follows that `C::value` must be an integral value.
  35. //!
  36. //! Finally, it is necessary to specialize the `IntegralConstant` template
  37. //! in the `boost::hana` namespace to tell Hana that a type is a model
  38. //! of `IntegralConstant`:
  39. //! @code
  40. //! namespace boost { namespace hana {
  41. //! template <>
  42. //! struct IntegralConstant<your_custom_tag> {
  43. //! static constexpr bool value = true;
  44. //! };
  45. //! }}
  46. //! @endcode
  47. //!
  48. //!
  49. //! Refined concept
  50. //! ---------------
  51. //! 1. `Constant` (free implementation of `value`)\n
  52. //! The `value` function required to be a `Constant` can be implemented
  53. //! as follows for `IntegralConstant`s:
  54. //! @code
  55. //! value<C>() == C::value
  56. //! @endcode
  57. //! The `to` function must still be provided explicitly for the model
  58. //! of `Constant` to be complete.
  59. //!
  60. //!
  61. //! Concrete models
  62. //! ---------------
  63. //! `hana::integral_constant`
  64. template <typename C>
  65. struct IntegralConstant;
  66. }} // end namespace boost::hana
  67. #endif // !BOOST_HANA_FWD_CONCEPT_INTEGRAL_CONSTANT_HPP