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