6 template <class T, class NotErrorCase>
9 This is a [link lazy_metafunction lazy template metafunction].
13 [[`T`] [[link accept accept] or [link reject reject] value]]
14 [[`NotErrorCase`] [[link metaprogramming_value template metaprogramming value]]]
19 Checks if `T` is a parsing error or not. When it is, the result is `T`. When it
20 is not, the result is `NotErrorCase`.
24 #include <boost/metaparse/unless_error.hpp>
26 [h1 Expression semantics]
28 For any `t` and `c` classes the following are equivalent:
32 boost::mpl::if_<is_error<t::type>::type, t, c>
36 #include <boost/metaparse/unless_error.hpp>
37 #include <boost/metaparse/accept.hpp>
38 #include <boost/metaparse/reject.hpp>
39 #include <boost/metaparse/start.hpp>
40 #include <boost/metaparse/string.hpp>
41 #include <boost/metaparse/define_error.hpp>
43 #include <type_traits>
45 using namespace boost::metaparse;
47 BOOST_METAPARSE_DEFINE_ERROR(sample_error, "Sample error message");
50 accept<std::integral_constant<int, 11>, BOOST_METAPARSE_STRING("foo"), start>;
53 accept<std::integral_constant<int, 13>, BOOST_METAPARSE_STRING("bar"), start>;
55 using reject1 = reject<sample_error, start>;
57 struct returns_accept1 { using type = accept1; };
58 struct returns_accept2 { using type = accept2; };
61 std::is_same<accept2, unless_error<accept1, accept2>::type>::type::value,
62 "it returns the second argument when the first argument is an accept"
66 std::is_same<reject1, unless_error<reject1, accept2>::type>::type::value,
67 "it returns the first argument when that is a reject"
73 unless_error<returns_accept1, returns_accept2>::type
75 "it supports lazy evaluation"