integral_constant.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*!
  2. @file
  3. Forward declares `boost::hana::integral_constant`.
  4. @copyright Louis Dionne 2013-2017
  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_INTEGRAL_CONSTANT_HPP
  9. #define BOOST_HANA_FWD_INTEGRAL_CONSTANT_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/detail/integral_constant.hpp>
  12. #include <cstddef>
  13. BOOST_HANA_NAMESPACE_BEGIN
  14. //! Creates an `integral_constant` holding the given compile-time value.
  15. //! @relates hana::integral_constant
  16. //!
  17. //! Specifically, `integral_c<T, v>` is a `hana::integral_constant`
  18. //! holding the compile-time value `v` of an integral type `T`.
  19. //!
  20. //!
  21. //! @tparam T
  22. //! The type of the value to hold in the `integral_constant`.
  23. //! It must be an integral type.
  24. //!
  25. //! @tparam v
  26. //! The integral value to hold in the `integral_constant`.
  27. //!
  28. //!
  29. //! Example
  30. //! -------
  31. //! @snippet example/integral_constant.cpp integral_c
  32. template <typename T, T v>
  33. constexpr integral_constant<T, v> integral_c{};
  34. //! @relates hana::integral_constant
  35. template <bool b>
  36. using bool_ = integral_constant<bool, b>;
  37. //! @relates hana::integral_constant
  38. template <bool b>
  39. constexpr bool_<b> bool_c{};
  40. //! @relates hana::integral_constant
  41. using true_ = bool_<true>;
  42. //! @relates hana::integral_constant
  43. constexpr auto true_c = bool_c<true>;
  44. //! @relates hana::integral_constant
  45. using false_ = bool_<false>;
  46. //! @relates hana::integral_constant
  47. constexpr auto false_c = bool_c<false>;
  48. //! @relates hana::integral_constant
  49. template <char c>
  50. using char_ = integral_constant<char, c>;
  51. //! @relates hana::integral_constant
  52. template <char c>
  53. constexpr char_<c> char_c{};
  54. //! @relates hana::integral_constant
  55. template <short i>
  56. using short_ = integral_constant<short, i>;
  57. //! @relates hana::integral_constant
  58. template <short i>
  59. constexpr short_<i> short_c{};
  60. //! @relates hana::integral_constant
  61. template <unsigned short i>
  62. using ushort_ = integral_constant<unsigned short, i>;
  63. //! @relates hana::integral_constant
  64. template <unsigned short i>
  65. constexpr ushort_<i> ushort_c{};
  66. //! @relates hana::integral_constant
  67. template <int i>
  68. using int_ = integral_constant<int, i>;
  69. //! @relates hana::integral_constant
  70. template <int i>
  71. constexpr int_<i> int_c{};
  72. //! @relates hana::integral_constant
  73. template <unsigned int i>
  74. using uint = integral_constant<unsigned int, i>;
  75. //! @relates hana::integral_constant
  76. template <unsigned int i>
  77. constexpr uint<i> uint_c{};
  78. //! @relates hana::integral_constant
  79. template <long i>
  80. using long_ = integral_constant<long, i>;
  81. //! @relates hana::integral_constant
  82. template <long i>
  83. constexpr long_<i> long_c{};
  84. //! @relates hana::integral_constant
  85. template <unsigned long i>
  86. using ulong = integral_constant<unsigned long, i>;
  87. //! @relates hana::integral_constant
  88. template <unsigned long i>
  89. constexpr ulong<i> ulong_c{};
  90. //! @relates hana::integral_constant
  91. template <long long i>
  92. using llong = integral_constant<long long, i>;
  93. //! @relates hana::integral_constant
  94. template <long long i>
  95. constexpr llong<i> llong_c{};
  96. //! @relates hana::integral_constant
  97. template <unsigned long long i>
  98. using ullong = integral_constant<unsigned long long, i>;
  99. //! @relates hana::integral_constant
  100. template <unsigned long long i>
  101. constexpr ullong<i> ullong_c{};
  102. //! @relates hana::integral_constant
  103. template <std::size_t i>
  104. using size_t = integral_constant<std::size_t, i>;
  105. //! @relates hana::integral_constant
  106. template <std::size_t i>
  107. constexpr size_t<i> size_c{};
  108. namespace literals {
  109. //! Creates a `hana::integral_constant` from a literal.
  110. //! @relatesalso boost::hana::integral_constant
  111. //!
  112. //! The literal is parsed at compile-time and the result is returned
  113. //! as a `llong<...>`.
  114. //!
  115. //! @note
  116. //! We use `llong<...>` instead of `ullong<...>` because using an
  117. //! unsigned type leads to unexpected behavior when doing stuff like
  118. //! `-1_c`. If we used an unsigned type, `-1_c` would be something
  119. //! like `ullong<-1>` which is actually `ullong<something huge>`.
  120. //!
  121. //!
  122. //! Example
  123. //! -------
  124. //! @snippet example/integral_constant.cpp literals
  125. template <char ...c>
  126. constexpr auto operator"" _c();
  127. }
  128. BOOST_HANA_NAMESPACE_END
  129. #endif // !BOOST_HANA_FWD_INTEGRAL_CONSTANT_HPP