Home | Libraries | People | FAQ | More |
template <class P, class T> struct always;
This is a parser combinator.
It accepts an input if and only if P
accepts it, but the result of parsing will be T
instead of the result P
returned.
#include <boost/metaparse/always.hpp>
For any p
parser and t
class the following are equivalent:
always<p, t> last_of<p, return_<t>>
#include <boost/metaparse/always.hpp> #include <boost/metaparse/lit_c.hpp> #include <boost/metaparse/start.hpp> #include <boost/metaparse/string.hpp> #include <boost/metaparse/is_error.hpp> #include <boost/metaparse/get_result.hpp> #include <type_traits> using namespace boost::metaparse; using always13 = always<lit_c<'x'>, std::integral_constant<int, 13>>; static_assert( !is_error<always13::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value, "always13 should accept x" ); static_assert( std::is_same< get_result<always13::apply<BOOST_METAPARSE_STRING("x"), start>>::type, std::integral_constant<int, 13> >::type::value, "the result of parsing should be the integral_constant type" ); static_assert( is_error<always13::apply<BOOST_METAPARSE_STRING("y"), start>>::type::value, "always13 should reject characters other than x" );