int_to_digit.qbk 1.4 KB

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