in_range.qbk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. [#in_range]
  2. [section in_range]
  3. [h1 Synopsis]
  4. namespace util
  5. {
  6. template <class LowerBound, class UpperBound, class Item>
  7. struct in_range;
  8. }
  9. This is a [link metafunction template metafunction] supporting
  10. [link currying currying].
  11. [table Arguments
  12. [[Name] [Type]]
  13. [[`LowerBound`] [[link boxed_value boxed integral value]]]
  14. [[`UpperBound`] [[link boxed_value boxed integral value]]]
  15. [[`Item`] [[link boxed_value boxed integral value]]]
  16. ]
  17. [h1 Description]
  18. It returns a boxed boolean value. The value is `true` when `Item` is in the
  19. range `[LowerBound..UpperBound]` and `false` otherwise. `boost::mpl::less_equal`
  20. is used for comparison.
  21. [h1 Header]
  22. #include <boost/metaparse/util/in_range.hpp>
  23. [h1 Expression semantics]
  24. For any `L`, `U` and `T` classes the following are equivalent:
  25. in_range<L, U>::apply<T>::type::value
  26. boost::mpl::less_equal<L, T>::type::value
  27. && boost::mpl::less_equal<T, U>::type::value
  28. [h1 Example]
  29. #include <boost/metaparse/util/in_range.hpp>
  30. #include <boost/mpl/int.hpp>
  31. using namespace boost::metaparse;
  32. static_assert(
  33. !util::in_range<
  34. boost::mpl::int_<11>,
  35. boost::mpl::int_<13>,
  36. boost::mpl::int_<10>
  37. >::type::value,
  38. "A value below the lower bound should not be in the range"
  39. );
  40. static_assert(
  41. !util::in_range<
  42. boost::mpl::int_<11>,
  43. boost::mpl::int_<13>,
  44. boost::mpl::int_<14>
  45. >::type::value,
  46. "A value above the upper bound should not be in the range"
  47. );
  48. static_assert(
  49. util::in_range<
  50. boost::mpl::int_<11>,
  51. boost::mpl::int_<13>,
  52. boost::mpl::int_<11>
  53. >::type::value,
  54. "The lower bound should be in the range"
  55. );
  56. static_assert(
  57. util::in_range<
  58. boost::mpl::int_<11>,
  59. boost::mpl::int_<13>,
  60. boost::mpl::int_<13>
  61. >::type::value,
  62. "The upper bound should be in the range"
  63. );
  64. static_assert(
  65. util::in_range<
  66. boost::mpl::int_<11>,
  67. boost::mpl::int_<13>,
  68. boost::mpl::int_<12>
  69. >::type::value,
  70. "A value between the bounds should be in the range"
  71. );
  72. static_assert(
  73. util::in_range<>
  74. ::apply<boost::mpl::int_<11>>::type
  75. ::apply<boost::mpl::int_<13>>::type
  76. ::apply<boost::mpl::int_<12>>::type
  77. ::type::value,
  78. "It should support currying"
  79. );
  80. [endsect]