1[#unless_error] 2[section unless_error] 3 4[h1 Synopsis] 5 6 template <class T, class NotErrorCase> 7 struct unless_error; 8 9This is a [link lazy_metafunction lazy template metafunction]. 10 11[table Arguments 12 [[Name] [Type]] 13 [[`T`] [[link accept accept] or [link reject reject] value]] 14 [[`NotErrorCase`] [[link metaprogramming_value template metaprogramming value]]] 15] 16 17[h1 Description] 18 19Checks if `T` is a parsing error or not. When it is, the result is `T`. When it 20is not, the result is `NotErrorCase`. 21 22[h1 Header] 23 24 #include <boost/metaparse/unless_error.hpp> 25 26[h1 Expression semantics] 27 28For any `t` and `c` classes the following are equivalent: 29 30 unless_error<t, c> 31 32 boost::mpl::if_<is_error<t::type>::type, t, c> 33 34[h1 Example] 35 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> 42 43 #include <type_traits> 44 45 using namespace boost::metaparse; 46 47 BOOST_METAPARSE_DEFINE_ERROR(sample_error, "Sample error message"); 48 49 using accept1 = 50 accept<std::integral_constant<int, 11>, BOOST_METAPARSE_STRING("foo"), start>; 51 52 using accept2 = 53 accept<std::integral_constant<int, 13>, BOOST_METAPARSE_STRING("bar"), start>; 54 55 using reject1 = reject<sample_error, start>; 56 57 struct returns_accept1 { using type = accept1; }; 58 struct returns_accept2 { using type = accept2; }; 59 60 static_assert( 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" 63 ); 64 65 static_assert( 66 std::is_same<reject1, unless_error<reject1, accept2>::type>::type::value, 67 "it returns the first argument when that is a reject" 68 ); 69 70 static_assert( 71 std::is_same< 72 accept2, 73 unless_error<returns_accept1, returns_accept2>::type 74 >::type::value, 75 "it supports lazy evaluation" 76 ); 77 78[endsect] 79 80