Re: Example verbatim snippet from X3 documentation "Attributes of Compound Components" fails to compile

Henri Menke <[email protected]> Mon, 12 Nov 2018 14:54:50 +1300
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
You need to include the header from Boost.Fusion to adapt std::pair.

#include <boost/spirit/home/x3.hpp>
#include <boost/fusion/adapted/std_pair.hpp> // <---

namespace x3 = boost::spirit::x3;

int main() {
    // the following parses "1.0 2.0" into a pair of double
    std::string input("1.0 2.0");
    std::string::iterator strbegin = input.begin();
    std::pair<double, double> p;
    x3::phrase_parse(strbegin, input.end(),
                     x3::double_ >> x3::double_, // parser grammar
                     x3::space,                  // delimiter grammar
                     p); // attribute to fill while parsing
}



On 12/11/18 1:17 PM, Chris Mileto wrote:
> 
> As an X3 newbie I am having trouble compiling the following verbatim snippet
> from the X3 documentation under the section entitled "
> <https://www.boost.org/doc/libs/develop/libs/spirit/doc/x3/html/spirit_x3/ab
> stracts/compound_attributes.html> Attributes of Compound Components" using
> either GNU or Microsoft, either C++14 or C++17 or any version of Boost with
> X3:
> 
> 
> #include <boost/spirit/home/x3.hpp>
> 
> namespace x3 = boost::spirit::x3;
> 
>  
> 
> int main()
> 
> {
> 
>             // the following parses "1.0 2.0" into a pair of double
> 
>             std::string input("1.0 2.0");
> 
>             std::string::iterator strbegin = input.begin();
> 
>             std::pair<double, double> p;
> 
>             x3::phrase_parse(strbegin, input.end(),
> 
>                 x3::double_ >> x3::double_,       // parser grammar
> 
>                 x3::space,                        // delimiter grammar
> 
>                 p);                               // attribute to fill while
> parsing
> 
> }
> 
>  
> 
> Compilation produces the following error:
> 
>  
> 
> error C2679: binary '=': no operator found which takes a right-hand operand
> of type 'double' (or there is no acceptable conversion)
> 
> c:\program files (x86)\microsoft visual
> studio\2017\community\vc\tools\msvc\14.15.26726\include\utility(276): note:
> could be 'std::pair<double,double> &std::pair<double,double>::operator
> =(volatile const std::pair<double,double> &)'
> 
> c:\tools\boost\boost\spirit\home\x3\support\traits\move_to.hpp(61): note:
> while trying to match the argument list '(Dest, double)'
> 
>         with
> 
>         [
> 
>             Dest=std::pair<double,double>
> 
>         ]
> 
>  
> 
> Thanks for any insight,
> 
> Chris
> 
>  
> 
> 
> 
> 
> _______________________________________________
> Spirit-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/spirit-general
>