2010-12-10 6 views
1

Ich habe den anderen Thread über copy or reference semantics for boost::spirt::qi::rule gelesen. Ich benutze Boost 1.42.Speichern einer boost :: spirit :: qi :: -Regel in einer std :: list

using boost::spirit::qi::phrase_parse; 
typedef boost::spirit::qi::rule < std::string::const_iterator, boost::spirit::ascii::space_type > rule_type; 
std::list <rule_type> ruleList; 
std::string const s("abcdef"); 
std::string::const_iterator iter = s.begin(), end = s.end(); 
std::cout << typeid(char_).name() << std::endl; 
ruleList.push_back(char_); 
ruleList.push_back(*ruleList.back()); 
assert(phrase_parse(iter, s.end(), ruleList.back(), boost::spirit::ascii::space)); 
assert(iter == s.end()); 

Dies irgendwie ...

Assertion `phrase_parse(iter, s.end(), ruleList.back(), traits::space())' failed. 
Aborted (core dumped) 

Gibt es eine Möglichkeit Regeln in einer STL-Liste oder deque zu speichern? (Referenzen sterben erst, wenn sie entfernt wurden).

Antwort

2

Mit Boost-V1.45, das (im Wesentlichen der Code von oben) funktioniert ohne Probleme (MSVC2010, g ++ 4.5.1):

#include <list> 
#include <string> 
#include <iostream> 
#include <boost/spirit/include/qi.hpp> 

using namespace boost::spirit; 

int main() 
{ 
    typedef qi::rule<std::string::const_iterator, ascii::space_type> rule_type; 
    std::list<rule_type> ruleList; 

    std::string const s("abcdef"); 
    std::string::const_iterator iter = s.begin(), end = s.end(); 
    std::cout << typeid(qi::char_).name() << std::endl; 

    ruleList.push_back(qi::char_); 
    ruleList.push_back(*ruleList.back()); 

    assert(qi::phrase_parse(iter, s.end(), ruleList.back(), ascii::space)); 
    assert(iter == s.end()); 

    return 0; 
} 
Deshalb

, gehe ich davon aus es einen Fehler in der Version von Spirit Sie verwende es.

0

Ich konnte Ihr Beispiel nicht kompilieren. Abgesehen von nicht using die richtigen Typen von ...::qi, fügten Sie eine () zum trait::space Typ hinzu.

Dies funktioniert w/o Problem für mich (Boost 1,44)

#include <boost/spirit/include/qi.hpp> 
#include <string> 
#include <vector> 
#include <cassert> 

using boost::spirit::qi::phrase_parse; 

typedef boost::spirit::qi::rule < std::string::const_iterator, boost::spirit::qi::space_type > rule_type; 

int main() { 

std::list <rule_type> ruleList; 
std::string const s("abcdef"); 
std::string::const_iterator iter = s.begin(), end = s.end(); 
ruleList.push_back(*boost::spirit::qi::char_); 
assert(phrase_parse(iter, s.end(), ruleList.back(), boost::spirit::qi::space)); 
assert(iter == s.end()); 

} 

~>g++ test.cpp && ./a.out
~>

Bitte beachten Sie, ich verwende qi::space_type und `qi::space anstelle des ascii Namespace. Ich habe keine Ahnung was/wo der trait Namensraum ist.

Verwandte Themen