1[#keyword] 2[section keyword] 3 4[h1 Synopsis] 5 6 template <class S, class ResultType = /* unspecified */> 7 struct keyword; 8 9This is a [link parser parser]. 10 11[table Arguments 12 [[Name] [Type]] 13 [[`S`] [[link string string]]] 14 [[`ResultType`] [[link metaprogramming_value template metaprogramming value]]] 15] 16 17[h1 Description] 18 19Parser accepting the keyword `S`. The result of parsing is `ResultType`, which 20is optional; when not given, the result of successful parsing is undefined. 21 22[h1 Header] 23 24 #include <boost/metaparse/keyword.hpp> 25 26[h1 Expression semantics] 27 28For any `r` class and `s` compile-time string that is built from the characters 29`c1` ... `cn` the following are equivalent: 30 31 keyword<s, r> 32 33 last_of<lit<c1>, /* ... */, lit<cn>, return_<r>> 34 35[h1 Example] 36 37 #include <boost/metaparse/keyword.hpp> 38 #include <boost/metaparse/string.hpp> 39 #include <boost/metaparse/start.hpp> 40 #include <boost/metaparse/get_result.hpp> 41 #include <boost/metaparse/is_error.hpp> 42 43 #include <type_traits> 44 45 using namespace boost::metaparse; 46 47 static_assert( 48 get_result< 49 keyword<BOOST_METAPARSE_STRING("for"), std::integral_constant<int, 13>> 50 ::apply<BOOST_METAPARSE_STRING("for"), start> 51 >::type::value == 13, 52 "the result of parsing the keyword is keyword's second argument" 53 ); 54 55 static_assert( 56 is_error< 57 keyword<BOOST_METAPARSE_STRING("for"), std::integral_constant<int, 13>> 58 ::apply<BOOST_METAPARSE_STRING("if"), start> 59 >::type::value, 60 "a word other than the keyword is an error" 61 ); 62 63[endsect] 64 65