Reading the documentation, I think the below should work correctly, but instead it fails to compile unless I don't pass output to the phrase_parse
call, in which case it works correctly, though I can't get the data I want. It seems that nvp_def has types of (string, unused_type, uin32_t)
which (as I read the documentation) would create a tuple as I'm expecting, but this obviously isn't the case. What am I missing to be able to get the parse data?
#include <boost/spirit/home/x3.hpp>
#include <tuple>
namespace x3 = boost::spirit::x3;
x3::rule<class idtype, std::string> const idrule = "idrule";
auto const idrule_def = x3::lexeme[+x3::char_("a-zA-Z0-9")];
x3::rule<class nvp, std::tuple<std::string, uint32_t>> const nvp = "nvp";
auto const nvp_def = idrule >> x3::char_(':') >> x3::hex;
BOOST_SPIRIT_DEFINE(idrule, nvp);
int main(int argc, char *argv[])
{
std::tuple<std::string, uint32_t> output;
const std::string total = "foo4bar:deadbeef";
std::string::const_iterator first = total.begin();
std::string::const_iterator const last = total.end();
bool r = x3::phrase_parse(first, last, nvp, x3::space, output);
}
Compile error (trying to assign a uint32_t from hex to a tuple):
/usr/include/boost/spirit/home/x3/support/traits/move_to.hpp:62: error: no match for ‘operator=’ (operand types are ‘std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int>’ and ‘std::remove_reference<unsigned int&>::type {aka unsigned int}’)
dest = std::move(src);
~~~~~^~~~~~~~~~~~~~~~