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