Search code examples
c++boost-spiritboost-spirit-x3

Spirit X3: Basic example for compound components does not compile


This code, taken verbatim from the x3 documentation, does not compile

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

namespace x3 = boost::spirit::x3;

int main(int argc, char* argv[]) {
    std::string input("(1.0, 2.0)");
    std::string::iterator strbegin = input.begin();
    std::pair<double, double> p;
    x3::parse(strbegin, input.end(),
        '(' >> x3::double_ >> ", " >> x3::double_ >> ')',
        p);
    return 0;
}

Tested with Boost 1.63,1.61 and Gcc 7,6.2 it fails with:

/home/dvd/Projects/personal/iforeader/main.cpp:27:4:   required from here
/home/dvd/Projects/personal/iforeader/3rdparty/boost/spirit/home/x3/support/traits/move_to.hpp:62:18: error: no match for ‘operator=’ (operand types are ‘std::pair<double, double>’ and ‘std::remove_reference<double&>::type {aka double}’)
         dest = std::move(src);

I'm missing something obvious?


Solution

  • The include

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

    is missing to allow the pair to be attribute compatible