0

Why does this not compile? The marked line gives me: "static assertion failed: The parser expects tuple-like attribute type". I would think that an std::tuple were the essence of "tuple-like"?

#include <string>
#include <tuple>
#include <boost/spirit/home/x3.hpp>

void parseInteger(std::string input) {
    namespace x3 = boost::spirit::x3;
    auto iter = input.begin();
    auto end_iter = input.end();
    int result;
    x3::parse(iter, end_iter, x3::int_, result);
}

void parseIntegerAndDouble(std::string input) {
    namespace x3 = boost::spirit::x3;
    auto iter = input.begin();
    auto end_iter = input.end();
    std::tuple<int, double> result;
    x3::parse(iter, end_iter, x3::int_ >> ' ' >> x3::double_, result); //Compile error!
}


int main(int, char **)
{
    parseInteger("567");
    parseIntegerAndDouble("321 3.1412");
    return 0;
}
Niels Holst
  • 586
  • 4
  • 9

1 Answers1

2

The trick is to include two additional header files:

#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/include/std_tuple.hpp>

This is a bit more magical than I like, but I've got a feeling I really don't want to know how this works!

Niels Holst
  • 586
  • 4
  • 9