1[#one_of] 2[section one_of] 3 4[h1 Synopsis] 5 6 template <class... Ps> 7 struct one_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 18It accepts an input when any of the `Ps...` parsers accept it. The result of 19parsing is the result of applying the first parser that accepts the input. The 20parsers are tried in order, therefore in case of ambiguous grammars the result 21of parsing depends on the order of the `Ps...` parsers. 22 23On compilers, which are not C++11-compliant, the maximum number of accepted 24parsers is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE` macro. Its default 25value is `20`. 26 27[h1 Header] 28 29 #include <boost/metaparse/one_of.hpp> 30 31[h1 Expression semantics] 32 33For any `p1`, ..., `pn` parsers, `s` compile-time string and `pos` source 34position 35 36 one_of<p1, ..., pn>::apply<s, pos> 37 38is equivalent to 39 40 pk::apply<s, pos> 41 42when there is a `k`, that `pi::apply<s, pos>::type` returns an error for every 43`i` in the range `[1..k)` and `pk::apply<s, pos>::type` doesn't return an error. 44 45The parser combinator returns an error when there is no such `k`. 46 47[h1 Example] 48 49 #include <boost/metaparse/one_of.hpp> 50 #include <boost/metaparse/lit_c.hpp> 51 #include <boost/metaparse/start.hpp> 52 #include <boost/metaparse/string.hpp> 53 #include <boost/metaparse/get_result.hpp> 54 #include <boost/metaparse/is_error.hpp> 55 56 using namespace boost::metaparse; 57 58 using whitespace = 59 one_of<lit_c<' '>, lit_c<'\n'>, lit_c<'\r'>, lit_c<'\t'>, lit_c<'\v'>>; 60 61 static_assert( 62 get_result< 63 whitespace::apply<BOOST_METAPARSE_STRING(" "), start> 64 >::type::value == ' ', 65 "the result of parsing should be the first character of the input" 66 ); 67 68 static_assert( 69 is_error<whitespace::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value, 70 "it should return an error when the input does not begin with a whitespace" 71 ); 72 73 74[endsect] 75 76