digit_to_int.qbk 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [#digit_to_int]
  2. [section digit_to_int]
  3. [h1 Synopsis]
  4. namespace util
  5. {
  6. template <class D>
  7. struct digit_to_int;
  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] character value]]
  14. ]
  15. [h1 Description]
  16. Converts a boxed character containing a value in the range `['0'..'9']` to an
  17. integer.
  18. [h1 Return value]
  19. It returns a [link boxed_value boxed] integer value.
  20. [h1 Header]
  21. #include <boost/metaparse/util/digit_to_int.hpp>
  22. [h1 Expression semantics]
  23. For any `C` boxed character value in the range `['0'..'9']` the following
  24. expressions are equivalent
  25. digit_to_int<>::apply<C>::type
  26. digit_to_int<C>::type
  27. digit_to_int_c<C::type::value>::type
  28. [h1 Example]
  29. #include <boost/metaparse/util/digit_to_int.hpp>
  30. #include <type_traits>
  31. using namespace boost::metaparse;
  32. struct nullary_metafunction_returning_4
  33. {
  34. using type = std::integral_constant<char, '4'>;
  35. };
  36. static_assert(
  37. util::digit_to_int<std::integral_constant<char, '0'>>::type::value == 0,
  38. "it should convert a character to the corresponding integer value"
  39. );
  40. static_assert(
  41. util::digit_to_int<>::type
  42. ::apply<std::integral_constant<char, '7'>>::type::value == 7,
  43. "it should support currying"
  44. );
  45. static_assert(
  46. util::digit_to_int<nullary_metafunction_returning_4>::type::value == 4,
  47. "it should support lazy evaluation"
  48. );
  49. [endsect]