Boost logo

Boost Users :

Subject: Re: [Boost-users] problem with xpressive sregex and stl::list::iterator
From: Richard (codemonkee_at_[hidden])
Date: 2011-09-29 21:52:49


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::list<boost::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<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _Alloc = std::allocator<boost::xpressive::basic_regex<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]()'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h:112: note: candidates are: std::_List_iterator<boost::xpressive::basic_regex<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >& std::_List_iterator<boost::xpressive::basic_regex<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::operator=(const std::_List_iterator<boost::xpressive::basic_regex<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)

as for the problem with using vector together with sregex, here is what I found on web
https://svn.boost.org/trac/boost/ticket/3712

At 2011-09-30 02:55:25,"Eric Niebler" <eric_at_[hidden]> wrote:
>On 9/29/2011 3:02 AM, Richard wrote:
>> hi,
>>
>> I am trying to use stl::list<boost::xpressive::sregex>, but the
>> following code cannot be complied
>>
>> stl::list<boost::xpressive::sregex> rxs;
>> sregex rex = boost::xpressive::sregex::compile("hello");
>> rxs.push_back(rex);
>> 50 std::list<boost::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 <boost/xpressive/xpressive_dynamic.hpp>
>
> int main()
> {
> std::list<boost::xpressive::sregex> rxs;
> boost::xpressive::sregex rex =
> boost::xpressive::sregex::compile("hello");
> rxs.push_back(rex);
> std::list<boost::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::vector<boost::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_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net