is_digit.qbk 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. [#is_digit]
  2. [section is_digit]
  3. [h1 Synopsis]
  4. namespace util
  5. {
  6. template <class C>
  7. struct is_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. [[`C`] [[link boxed_value boxed] character value]]
  14. ]
  15. [h1 Description]
  16. Checks if `C` is a digit value or not. Returns a boxed boolean value.
  17. [h1 Header]
  18. #include <boost/metaparse/util/is_digit.hpp>
  19. [h1 Expression semantics]
  20. The following expressions are equivalent:
  21. is_digit<boost::mpl::char_<'0'>>::type
  22. is_digit<>::apply<boost::mpl::char_<'0'>>::type
  23. boost::mpl::true_
  24. The following expressions are also equivalent:
  25. is_digit<>::apply<c>::type
  26. boost::mpl::false_
  27. [h1 Example]
  28. #include <boost/metaparse/util/is_digit.hpp>
  29. #include <type_traits>
  30. using namespace boost::metaparse;
  31. struct returns_char
  32. {
  33. using type = std::integral_constant<char, '0'>;
  34. };
  35. static_assert(
  36. util::is_digit<std::integral_constant<char, '0'>>::type::value,
  37. "digit character should be a digit"
  38. );
  39. static_assert(
  40. !util::is_digit<std::integral_constant<char, 'x'>>::type::value,
  41. "letter should not be a digit"
  42. );
  43. static_assert(
  44. util::is_digit<>::type::apply<std::integral_constant<char, '0'>>::type::value,
  45. "it should support currying"
  46. );
  47. static_assert(
  48. util::is_digit<returns_char>::type::value,
  49. "it should support lazy evaluation"
  50. );
  51. [endsect]