is_error.qbk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. [#is_error]
  2. [section is_error]
  3. [h1 Synopsis]
  4. template <class C>
  5. struct is_error;
  6. This is a [link lazy_metafunction lazy template metafunction] that supports
  7. [link currying currying].
  8. [table Arguments
  9. [[Name] [Type]]
  10. [[`C`] [[link accept accept] or [link reject reject] value]]
  11. ]
  12. [h1 Description]
  13. Determines if `C` is a parsing error or not. Returns a [link boxed_value boxed]
  14. boolean value.
  15. [h1 Header]
  16. #include <boost/metaparse/is_error.hpp>
  17. [h1 Expression semantics]
  18. For any `e` parsing error `is_error<c>::type` is a wrapped compile-time `true`
  19. value, for any other `c` class `is_error<c>::type` is a wrapped compile-time
  20. `false` value.
  21. [h1 Example]
  22. #include <boost/metaparse/is_error.hpp>
  23. #include <boost/metaparse/accept.hpp>
  24. #include <boost/metaparse/reject.hpp>
  25. #include <boost/metaparse/string.hpp>
  26. #include <boost/metaparse/start.hpp>
  27. #include <boost/metaparse/define_error.hpp>
  28. #include <type_traits>
  29. using namespace boost::metaparse;
  30. BOOST_METAPARSE_DEFINE_ERROR(sample_error, "Sample error message");
  31. struct returns_reject
  32. {
  33. typedef reject<sample_error, start> type;
  34. };
  35. static_assert(
  36. !is_error<
  37. accept<
  38. std::integral_constant<int, 13>,
  39. BOOST_METAPARSE_STRING("foo"),
  40. start
  41. >
  42. >::type::value,
  43. "an accept should not be an error"
  44. );
  45. static_assert(
  46. is_error<reject<sample_error, start>>::type::value,
  47. "an reject should be an error"
  48. );
  49. static_assert(
  50. is_error<>::type::apply<reject<sample_error, start>>::type::value,
  51. "it should support currying"
  52. );
  53. static_assert(
  54. is_error<returns_reject>::type::value,
  55. "it should support lazy evaluation"
  56. );
  57. [endsect]