in_range_c.qbk 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [#in_range_c]
  2. [section in_range_c]
  3. [h1 Synopsis]
  4. namespace util
  5. {
  6. template <class T, T LowerBound, T UpperBound>
  7. struct in_range_c
  8. {
  9. template <class U>
  10. struct apply;
  11. };
  12. }
  13. This is a [link metafunction_class template metafunction class].
  14. [table Arguments
  15. [[Name] [Type]]
  16. [[`T`] [integral type]]
  17. [[`LowerBound`] [value of type `T`]]
  18. [[`UpperBound`] [value of type `T`]]
  19. [[`U`] [[link boxed_value boxed integral value]]]
  20. ]
  21. [h1 Description]
  22. Metafunction class verifying that `U` is in the `[LowerBound..UpperBound]` range
  23. or not.
  24. [h1 Header]
  25. #include <boost/metaparse/util/in_range_c.hpp>
  26. [h1 Expression semantics]
  27. For any `T` integral type, `A`, `B` values of type `T` and `C` wrapped value the
  28. following are equivalent:
  29. in_range_c<T, A, B>::apply<C>::type::value
  30. A <= C::type::value && C::type::value <= B
  31. [h1 Example]
  32. #include <boost/metaparse/util/in_range_c.hpp>
  33. #include <type_traits>
  34. using namespace boost::metaparse;
  35. static_assert(
  36. !util::in_range_c<int, 11, 13>
  37. ::apply<std::integral_constant<int, 10>>::type::value,
  38. "A value below the lower bound should not be in the range"
  39. );
  40. static_assert(
  41. !util::in_range_c<int, 11, 13>
  42. ::apply<std::integral_constant<int, 14>>::type::value,
  43. "A value above the upper bound should not be in the range"
  44. );
  45. static_assert(
  46. util::in_range_c<int, 11, 13>
  47. ::apply<std::integral_constant<int, 11>>::type::value,
  48. "The lower bound should be in the range"
  49. );
  50. static_assert(
  51. util::in_range_c<int, 11, 13>
  52. ::apply<std::integral_constant<int, 13>>::type::value,
  53. "The upper bound should be in the range"
  54. );
  55. static_assert(
  56. util::in_range_c<int, 11, 13>
  57. ::apply<std::integral_constant<int, 12>>::type::value,
  58. "A value between the bounds should be in the range"
  59. );
  60. [endsect]