• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#int_to_digit]
2[section int_to_digit]
3
4[h1 Synopsis]
5
6  namespace util
7  {
8    template <class D>
9    struct int_to_digit;
10  }
11
12This is a [link lazy_metafunction lazy template metafunction] that supports
13[link currying currying].
14
15[table Arguments
16  [[Name] [Type]]
17  [[`D`]  [[link boxed_value boxed] integer value]]
18]
19
20[h1 Description]
21
22Converts a boxed integer value in the range `[0-9]` to a character representing
23that decimal value.
24
25[h1 Header]
26
27  #include <boost/metaparse/util/int_to_digit.hpp>
28
29[h1 Expression semantics]
30
31The following pairs of expressions are equivalent
32
33  int_to_digit<boost::mpl::int_<0>>::type
34  boost::mpl::char_<'0'>
35
36  int_to_digit<boost::mpl::int_<9>>::type
37  boost::mpl::char_<'9'>
38
39[h1 Example]
40
41  #include <boost/metaparse/util/int_to_digit.hpp>
42
43  #include <type_traits>
44
45  using namespace boost::metaparse;
46
47  struct nullary_metafunction_returning_4
48  {
49    using type = std::integral_constant<int, 4>;
50  };
51
52  static_assert(
53    util::int_to_digit<std::integral_constant<int, 0>>::type::value == '0',
54    "it should convert an integer value to the corresponding character"
55  );
56
57  static_assert(
58    util::int_to_digit<>::type
59      ::apply<std::integral_constant<int, 7>>::type::value == '7',
60    "it should support currying"
61  );
62
63  static_assert(
64    util::int_to_digit<nullary_metafunction_returning_4>::type::value == '4',
65    "it should support lazy evaluation"
66  );
67
68[endsect]
69
70