problem with xpressive sregex and stl::list::iterator
hi, I am trying to use stl::listboost::xpressive::sregex, but the following code cannot be complied stl::listboost::xpressive::sregex rxs; sregex rex = boost::xpressive::sregex::compile("hello"); rxs.push_back(rex); 50 std::listboost::xpressive::sregex::iterator it; 51 52 for (it= rxs.begin(); it != rxs.end(); it++) 53 { //do something } line 52, "it= rxs.begin()" cannot be complied, it said the no match operator =., what is wrong? by the way, I cannot use std::vectorboost::xpressive::sregex, it compiled failed. I searched on web, it is said there is a bug with this issue. I do not want to change the version of boost library I used, so let's ignore this issue at the moment. thanks. Richard.
On 9/29/2011 3:02 AM, Richard wrote:
hi,
I am trying to use stl::listboost::xpressive::sregex, but the following code cannot be complied
stl::listboost::xpressive::sregex rxs; sregex rex = boost::xpressive::sregex::compile("hello"); rxs.push_back(rex); 50 std::listboost::xpressive::sregex::iterator it; 51 52 for (it= rxs.begin(); it != rxs.end(); it++) 53 { //do something }
line 52, "it= rxs.begin()" cannot be complied, it said the no match operator =., what is wrong?
The following program compiles for me:
#include <list>
#include
by the way, I cannot use std::vectorboost::xpressive::sregex, it compiled failed. I searched on web, it is said there is a bug with this issue. I do not want to change the version of boost library I used, so let's ignore this issue at the moment.
I don't remember that bug. Can you send a link to the ticket or to the mailing list discussion? -- Eric Niebler BoostPro Computing http://www.boostpro.com
thanks, I know the reason now.
it is because I have declared const on the member function where I iterate the sregex object.
after I removed the const declaration, the compile passed. but I am still curious, I am not changing
anything when I iterate the sregex object, why I cannot use the const declareation. To make it clear,
I give a more complete formulation of the problem I encountered.
class A
{
public:
bool Match(const string& str) const;
private:
list<sregex> mRegexs;
}
bool A::Match(const string& str) const
{
std::listboost::xpressive::sregex::iterator it;
for (it=mRegexs.begin(); it != mRegexs.end(); it++)
{
if (regex_match(str, *it))
{
return true;
}
else
{
return false;
}
}
return true;
}
in the above code, if I removed "const" declaration on the member function Match, the compilation passed, otherwise, there is error message like the following:
myclass.cpp:57: error: no match for 'operator=' in 'it = ((const Myclass*)this)->Myclass::mRegexs.std::list<_Tp, _Alloc>::begin [with _Tp = boost::xpressive::basic_regex<__gnu_cxx::__normal_iterator
On 9/29/2011 3:02 AM, Richard wrote:
hi,
I am trying to use stl::listboost::xpressive::sregex, but the following code cannot be complied
stl::listboost::xpressive::sregex rxs; sregex rex = boost::xpressive::sregex::compile("hello"); rxs.push_back(rex); 50 std::listboost::xpressive::sregex::iterator it; 51 52 for (it= rxs.begin(); it != rxs.end(); it++) 53 { //do something }
line 52, "it= rxs.begin()" cannot be complied, it said the no match operator =., what is wrong?
The following program compiles for me:
#include <list> #include
int main() { std::listboost::xpressive::sregex rxs; boost::xpressive::sregex rex = boost::xpressive::sregex::compile("hello"); rxs.push_back(rex); std::listboost::xpressive::sregex::iterator it;
for (it= rxs.begin(); it != rxs.end(); it++) { //do something } }
So I don't know what the problem could be. What compiler/std-library are you using, and what version of boost?
by the way, I cannot use std::vectorboost::xpressive::sregex, it compiled failed. I searched on web, it is said there is a bug with this issue. I do not want to change the version of boost library I used, so let's ignore this issue at the moment.
I don't remember that bug. Can you send a link to the ticket or to the mailing list discussion?
-- Eric Niebler BoostPro Computing http://www.boostpro.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
thanks, I know the reason now.
it is because I have declared const on the member function where I iterate the sregex object. after I removed the const declaration, the compile passed. but I am still curious, I am not changing anything when I iterate the sregex object, why I cannot use the const declareation. To make it clear, I give a more complete formulation of the problem I encountered.
You have to use std::listboost::xpressive::sregex::const_iterator if you want to iterate over a const list. This is because the non-const iterator allows doing things like *it = some_new_value; which would violate const-correctness. Regards, Nate
participants (3)
-
Eric Niebler
-
Nathan Ridge
-
Richard