// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include #include #include #include using boost::metaparse::foldl1; using boost::metaparse::build_parser; using boost::metaparse::transform; using boost::metaparse::one_of_c; using boost::metaparse::entire_input; using boost::metaparse::util::digit_to_int; using boost::mpl::int_; using boost::mpl::plus; using boost::mpl::times; /* * The grammar * * expression ::= ('1' | '0')* */ struct next_element { template struct apply : plus >, B> {}; }; typedef foldl1, digit_to_int<> >, int_<0>, next_element> S; typedef build_parser > binary_parser; template struct binary : binary_parser::apply::type {}; #ifdef _STR # error _STR already defined #endif #define _STR BOOST_METAPARSE_STRING #if BOOST_METAPARSE_STD < 2011 int main() { using std::cout; using std::endl; using boost::metaparse::string; cout << binary >::value << endl << binary >::value << endl << binary >::value << endl; } #else int main() { using std::cout; using std::endl; cout << binary<_STR("100")>::value << endl << binary<_STR("1011")>::value << endl << binary<_STR("1")>::value << endl; } #endif