digit_to_int_c.qbk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [#digit_to_int_c]
  2. [section digit_to_int_c]
  3. [h1 Synopsis]
  4. namespace util
  5. {
  6. template <char D>
  7. struct digit_to_int_c;
  8. }
  9. This is a template class similar to a [link metafunction template metafunction]
  10. but taking a `char` value as argument.
  11. [table Arguments
  12. [[Name] [Type]]
  13. [[`D`] [character value]]
  14. ]
  15. [h1 Description]
  16. Converts a character containing a value in the range `['0'..'9']` to an integer.
  17. [h1 Return value]
  18. It returns a [link boxed_value boxed] integer value.
  19. [h1 Header]
  20. #include <boost/metaparse/util/digit_to_int_c.hpp>
  21. [h1 Expression semantics]
  22. The following pairs of expressions are equivalent
  23. digit_to_int_c<'0'>::type
  24. boost::mpl::int_<0>
  25. digit_to_int_c<'9'>::type
  26. boost::mpl::int_<9>
  27. [h1 Example]
  28. #include <boost/metaparse/util/digit_to_int_c.hpp>
  29. using namespace boost::metaparse;
  30. static_assert(
  31. util::digit_to_int_c<'0'>::type::value == 0,
  32. "it should convert a character to the corresponding integer value"
  33. );
  34. static_assert(
  35. util::digit_to_int_c<'3'>::type::value == 3,
  36. "it should convert a character to the corresponding integer value"
  37. );
  38. static_assert(
  39. util::digit_to_int_c<'9'>::type::value == 9,
  40. "it should convert a character to the corresponding integer value"
  41. );
  42. [endsect]