1[#first_of] 2[section first_of] 3 4[h1 Synopsis] 5 6 template <class... Ps> 7 struct first_of; 8 9This is a [link parser_combinator parser combinator]. 10 11[table Arguments 12 [[Name] [Type]] 13 [[`Ps`] [[link parser parser]s]] 14] 15 16[h1 Description] 17 18`first_of` applies the `Ps...` parsers in sequence. It accepts an input when all 19parsers accept it. The result of parsing is the result of the first parser. 20 21On compilers, which are not C++11-compliant, the maximum number of parsers 22`first_of` accepts can be specified with the 23`BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE` macro. Its default value is `5`. 24 25[h1 Header] 26 27 #include <boost/metaparse/first_of.hpp> 28 29[h1 Expression semantics] 30 31For any `p1`, ... `pn` parsers 32 33 first_of<p1, ..., pn> 34 35is equivalent to 36 37 nth_of_c<0, p1, ..., pn> 38 39[h1 Example] 40 41 #include <boost/metaparse/first_of.hpp> 42 #include <boost/metaparse/int_.hpp> 43 #include <boost/metaparse/lit_c.hpp> 44 #include <boost/metaparse/string.hpp> 45 #include <boost/metaparse/start.hpp> 46 #include <boost/metaparse/is_error.hpp> 47 #include <boost/metaparse/get_result.hpp> 48 49 #include <type_traits> 50 51 using namespace boost::metaparse; 52 53 using int_with_semicolon = first_of<int_, lit_c<';'>>; 54 55 static_assert( 56 is_error< 57 int_with_semicolon::apply<BOOST_METAPARSE_STRING("13"), start> 58 >::type::value, 59 "int without semicolon is rejected" 60 ); 61 62 static_assert( 63 get_result< 64 int_with_semicolon::apply<BOOST_METAPARSE_STRING("13;"), start> 65 >::type::value, 66 "the result is the result of the first parser" 67 ); 68 69[endsect] 70 71