Je capture des données dans un boost :: circular_buffer et je voudrais maintenant effectuer une recherche regex sur le contenu mais j'ai du mal à obtenir boost :: regex pour comprendre comment regarder le buffer.Comment utiliser boost :: regex sur un buffer :: boost circulaire?
Voici une version allégée du genre de chose que je voudrais faire en fonction de l'exemple here:
// Set up a pre-populated data buffer as an example
std::string test = "Fli<usefuldata>bble";
boost::circular_buffer<char> dataBuff;
for (std::string::iterator it = test.begin(); it != test.end(); ++it)
{
dataBuff.push_back(*it);
}
// Set up the regex
static const boost::regex e("<\\w*>");
std::string::const_iterator start, end;
start = dataBuff.begin(); // <-- error C2679
end = dataBuff.end();
boost::match_flag_type flags = boost::match_default;
// Try and find something of interest in the buffer
boost::match_results<std::string::const_iterator> what;
if (regex_search(start, end, what, e, flags))
{
// Do something - we found what we're after...
}
I (je pense tout à fait compréhensible) obtenir cette erreur lorsque je tente de compiler:
1>c:\projects\ProtocolBufferProcessor\ProtocolBufferProcessor.h(53): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'boost::cb_details::iterator<Buff,Traits>' (or there is no acceptable conversion)
1> with
1> [
1> Buff=boost::circular_buffer<char>,
1> Traits=boost::cb_details::nonconst_traits<std::allocator<char>>
1> ]
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xstring(435): could be 'std::_String_iterator<_Elem,_Traits,_Alloc> &std::_String_iterator<_Elem,_Traits,_Alloc>::operator =(const std::_String_iterator<_Elem,_Traits,_Alloc> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::_String_iterator<_Elem,_Traits,_Alloc>, boost::cb_details::iterator<Buff,Traits>)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> and
1> [
1> Buff=boost::circular_buffer<char>,
1> Traits=boost::cb_details::nonconst_traits<std::allocator<char>>
1> ]
... mais y a-t-il autre chose que je puisse faire sinon créer un caractère std :: string par caractère à partir du tampon circulaire chaque fois que j'exécute l'expression rationnelle? J'utilise Boost v1.54 si ça fait une différence. J'utilise Boost 1.51.
essayer d'utiliser auto pour 'start' et les variables 'fin' et decltype (début) en tant que paramètre de type pour "quoi" variable. – Slava
J'ai essayé de changer '' auto start = dataBuff.begin(); 'mais j'obtiens' l'erreur C4430: spécificateur de type manquant - int supposé. Note: C++ ne supporte pas default-int' –
bien, à proprement parler auto et decltype ne sont pas nécessaires, vous pouvez simplement mettre les bons types d'itérateurs (pour le tampon circulaire) manuellement. Mais c'est un problème. Quel compilateur utilisez-vous? – Slava