2016-04-07 8 views
1

schrieb ich einen mathematischen Ausdruck Parser-Boost-Geist verwenden, die einen einfachen Leistungs Ausdruck (minimal Beispiel eines viel größeren Parser) analysiert:boost :: spirit und Intel Compiler Compiler-Fehler

#include <iostream> 
#include <boost/spirit/include/phoenix_operator.hpp> 
#include <boost/spirit/include/qi.hpp> 
#include <cmath> 
#include <string> 
using namespace std; 

namespace qi = boost::spirit::qi; 
namespace ascii = boost::spirit::ascii; 

struct power_ { 
    template <typename X, typename Y> struct result { 
     typedef X type; 
    }; 

    template <typename X, typename Y> X operator()(X x, Y y) const { 
     return std::pow(x, y); 
    } 
}; 

struct math : qi::grammar<std::string::const_iterator, double(), 
          ascii::space_type> { 
    math() : math::base_type(expr) { 
     boost::phoenix::function<power_> power; 

     expr = factor[qi::_val = qi::_1]; 

     factor = arg[qi::_val = qi::_1] >> 
       *("**" >> arg [qi::_val = power(qi::_val, qi::_1)]); 

     arg = qi::double_[qi::_val = qi::_1]; 
    } 

    qi::rule<std::string::const_iterator, double(), ascii::space_type> expr, arg, factor; 
}; 

int main(int argc, char **argv){ 
    math math; 

    string expr = "2**3"; 
    double result; 

    string::const_iterator iter = expr.begin(); 
    string::const_iterator end = expr.end(); 
    phrase_parse(iter, end, math, ascii::space, result); 

    cout << "Expression: " << expr << endl; 
    cout << "Result: " << result << endl; 

    return 0; 
} 

Dieser Code kompiliert fein beide unter Verwendung von GCC 4.8.4 und Clang 3.9, ergibt aber einen großen Übersetzungsfehler beim Kompilieren mit dem Intel-Compiler (Version 12.1.6). Der relevante Teil des Compilers ausgegeben

/user/home/gent/vsc408/vsc40826/boost_1_60_0/build/include/boost/utility/result_of.hpp(189): error: too few arguments for class template "power_::result" 
    struct result_of_nested_result : F::template result<FArgs> 

Dies scheint mit boost :: result_of zu einer Ausgabe zu zeigen und C 11 ++, wie http://www.boost.org/doc/libs/1_56_0/libs/utility/utility.htm#result_of erwähnt. Allerdings, wenn ich die Definition von struct power_ ändern:

struct power_ { 
    template <class> struct result; 

    template <class F, typename X, typename Y> 
    struct result < F(X, Y) > { 
     typedef X type; 
    }; 

    template <typename X, typename Y> X operator()(X x, Y y) const { 
     return std::pow(x, y); 
    } 
}; 

bekomme ich noch einen Fehler:

/user/home/gent/vsc408/vsc40826/boost_1_60_0/build/include/boost/phoenix/core/detail/preprocessed/function_eval_10.hpp(135): error: initial value of reference to non-const must be an lvalue 
        return boost::phoenix::eval(f, ctx)(help_rvalue_deduction(boost::phoenix::eval(a0, ctx)) , help_rvalue_deduction(boost::phoenix::eval(a1, ctx))); 

#define BOOST_RESULT_OF_USE_DECLTYPE vor jedem Geist Hinzufügen umfasst hilft auch nicht, als Compilation dann nicht auf den ersten Geist umfassen .

Weiß jemand, wie man dieses Problem löst?

+0

Das Problem tritt nur für Boost-Versionen höher als 1,56 auf. –

Antwort

1

Ok, nur diese eine aus. Boost :: Phoenix scheint durch Referenz auf Return zurückgegangen zu sein. Die folgende Version von struct power_ funktioniert:

struct power_ { 
    template <class> struct result; 

    template <class F, typename X, typename Y> 
    struct result < F(X, Y) > { 
     typedef X& type; 
    }; 

    template <typename X, typename Y> X& operator()(X &x, Y y) const { 
     x = std::pow(x, y); 
     return x; 
    } 
};