1

I'm trying to use boost::cregexp_iterator, as exaplined in http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/ref/regex_iterator.html

// Loop through all the patterns
auto sessionReconstructionsEnd = _sessionReconstructions.end();

for (auto sr = _sessionReconstructions.begin(); sr != sessionReconstructionsEnd; ++sr) {
    const std::string& pattern = sr->first;
    const auto& editors = sr->second;

    regex re(pattern);

        ...
    for (auto session = sessions.begin(); session != sessionsEnd; ++session) {


        for (size_t chunkNumber = 0; chunkNumber < sessionChunks.size(); ++chunkNumber) {
            const auto& chunkData = sessionChunks[chunkNumber].data;


            cregex_iterator reIteratorEnd;
            cregex_iterator reIterator(
                reinterpret_cast<const char*>(chunkData.data()),
                reinterpret_cast<const char*>(chunkData.data()) + chunkData.size(),
                re); // Here the search is being done...

All the other code is commented out. I get the following error:

               ^
In file included from /usr/include/boost/regex/v4/regex.hpp:67:0,
                 from /usr/include/boost/regex.hpp:31,
                 from LGEJobConfiguration.cpp:4:
/usr/include/boost/regex/v4/basic_regex.hpp: In instantiation of ‘boost::basic_regex<charT, traits>::basic_regex(const boost::basic_regex<charT, traits>&) [with charT = char; traits = boost::regex_traits<char>]’:
/usr/include/boost/regex/v4/regex_iterator.hpp:52:43:   required from ‘boost::regex_iterator_implementation<BidirectionalIterator, charT, traits>::regex_iterator_implementation(const regex_type*, BidirectionalIterator, boost::regex_constants::match_flag_type) [with BidirectionalIterator = const char*; charT = char; traits = boost::regex_traits<char>; boost::regex_iterator_implementation<BidirectionalIterator, charT, traits>::regex_type = boost::basic_regex<char, boost::regex_traits<char> >; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]’
/usr/include/boost/regex/v4/regex_iterator.hpp:113:46:   required from ‘boost::regex_iterator<BidirectionalIterator, charT, traits>::regex_iterator(BidirectionalIterator, BidirectionalIterator, const regex_type&, boost::regex_constants::match_flag_type) [with BidirectionalIterator = const char*; charT = char; traits = boost::regex_traits<char>; boost::regex_iterator<BidirectionalIterator, charT, traits>::regex_type = boost::basic_regex<char, boost::regex_traits<char> >; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]’
LGEJobConfiguration.cpp:543:8:   required from here
/usr/include/boost/regex/v4/basic_regex.hpp:344:29: error: use of deleted function ‘boost::shared_ptr<boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char> > >::shared_ptr(const boost::shared_ptr<boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char> > >&)’
       : m_pimpl(that.m_pimpl) {}
                             ^
In file included from /usr/include/boost/shared_ptr.hpp:17:0,
                 from /usr/include/boost/regex/v4/regex_workaround.hpp:43,
                 from /usr/include/boost/regex/v4/regex.hpp:32,
                 from /usr/include/boost/regex.hpp:31,
                 from LGEJobConfiguration.cpp:4:
/usr/include/boost/smart_ptr/shared_ptr.hpp:168:25: note: ‘boost::shared_ptr<boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char> > >::shared_ptr(const boost::shared_ptr<boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char> > >&)’ is implicitly declared as deleted because ‘boost::shared_ptr<boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char> > >’ declares a move constructor or move assignment operator
 template<class T> class shared_ptr
                         ^
/usr/include/boost/smart_ptr/shared_ptr.hpp: In instantiation of ‘boost::shared_ptr<T>& boost::shared_ptr<T>::operator=(const boost::shared_ptr<T>&) [with T = boost::re_detail::named_subexpressions]’:
/usr/include/boost/regex/v4/match_results.hpp:549:20:   required from ‘void boost::match_results<BidiIterator, Allocator>::set_named_subs(boost::shared_ptr<boost::re_detail::named_subexpressions>) [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >]’
/usr/include/boost/regex/v4/perl_matcher_common.hpp:265:7:   required from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::find_imp() [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; traits = boost::regex_traits<char>]’
/usr/include/boost/regex/v4/perl_matcher_common.hpp:230:20:   required from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::find() [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; traits = boost::regex_traits<char>]’
/usr/include/boost/regex/v4/regex_search.hpp:56:24:   required from ‘bool boost::regex_search(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type, BidiIterator) [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; charT = char; traits = boost::regex_traits<char>; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]’
/usr/include/boost/smart_ptr/shared_ptr.hpp:168:25: note: ‘boost::shared_ptr<boost::re_detail::named_subexpressions>::shared_ptr(const boost::shared_ptr<boost::re_detail::named_subexpressions>&)’ is implicitly declared as deleted because ‘boost::shared_ptr<boost::re_detail::named_subexpressions>’ declares a move constructor or move assignment operator
 template<class T> class shared_ptr
                         ^
In file included from /usr/include/boost/regex/v4/regex.hpp:82:0,
                 from /usr/include/boost/regex.hpp:31,
                 from LGEJobConfiguration.cpp:4:
/usr/include/boost/regex/v4/match_results.hpp: In instantiation of ‘boost::match_results<BidiIterator, Allocator>::match_results(const boost::match_results<BidiIterator, Allocator>&) [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >]’:
/usr/include/boost/regex/v4/perl_matcher_non_recursive.hpp:134:76:   required from ‘boost::re_detail::saved_recursion<Results>::saved_recursion(int, const boost::re_detail::re_syntax_base*, Results*) [with Results = boost::match_results<const char*>]’
/usr/include/boost/regex/v4/perl_matcher_non_recursive.hpp:342:4:   required from ‘void boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::push_recursion(int, const boost::re_detail::re_syntax_base*, boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::results_type*) [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; traits = boost::regex_traits<char>; boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::results_type = boost::match_results<const char*>]’
/usr/include/boost/regex/v4/perl_matcher_non_recursive.hpp:935:127:   required from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_endmark() [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; traits = boost::regex_traits<char>]’
/usr/include/boost/regex/v4/perl_matcher_non_recursive.hpp:147:7:   required from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_all_states() [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; traits = boost::regex_traits<char>]’
/usr/include/boost/regex/v4/perl_matcher_common.hpp:323:21:   [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/boost/regex/v4/perl_matcher_common.hpp:230:20:   required from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::find() [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; traits = boost::regex_traits<char>]’
/usr/include/boost/regex/v4/regex_search.hpp:56:24:   required from ‘bool boost::regex_search(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type, BidiIterator) [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; charT = char; traits = boost::regex_traits<char>; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]’
/usr/include/boost/regex/v4/regex_search.hpp:42:55:   required from ‘bool boost::regex_search(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with BidiIterator = const char*; Allocator = std::allocator<boost::sub_match<const char*> >; charT = char; traits = boost::regex_traits<char>; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]’
/usr/include/boost/regex/v4/regex_iterator.hpp:56:54:   required from ‘bool boost::regex_iterator_implementation<BidirectionalIterator, charT, traits>::init(BidirectionalIterator) [with BidirectionalIterator = const char*; charT = char; traits = boost::regex_traits<char>]’
/usr/include/boost/regex/v4/regex_iterator.hpp:115:10:   required from ‘boost::regex_iterator<BidirectionalIterator, charT, traits>::regex_iterator(BidirectionalIterator, BidirectionalIterator, const regex_type&, boost::regex_constants::match_flag_type) [with BidirectionalIterator = const char*; charT = char; traits = boost::regex_traits<char>; boost::regex_iterator<BidirectionalIterator, charT, traits>::regex_type = boost::basic_regex<char, boost::regex_traits<char> >; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]’
LGEJobConfiguration.cpp:543:8:   required from here
/usr/include/boost/regex/v4/match_results.hpp:81:130: error: use of deleted function ‘boost::shared_ptr<boost::re_detail::named_subexpressions>::shared_ptr(const boost::shared_ptr<boost::re_detail::named_subexpressions>&)’
       : m_subs(m.m_subs), m_named_subs(m.m_named_subs), m_last_closed_paren(m.m_last_closed_paren), m_is_singular(m.m_is_singular) 

what the problem?

UPDATE: the problem is with the flag --std=c++11 - I'm posting another post for this issue. UPDATE2: The problem is I was using an old version of boost (1.4.3), moving to lastest solved it

Guy L
  • 2,824
  • 2
  • 27
  • 37
  • Looks like a cascade of errors. Does the example on that doc page work? –  Mar 27 '14 at 23:13
  • 1
    it would help if you showed what line number is marked. We're having to guess too many things here to really be of any help – sehe Mar 28 '14 at 07:37
  • @sehe - next time I'll post line numbers as well... – Guy L Mar 28 '14 at 10:26
  • @sln - I think it's the --std issue, I'm trying to upgrade my boost version and then I'll see – Guy L Mar 28 '14 at 10:26
  • 1
    @GuyL actually, making it self-contained beats grappling with line numbers. People can just reproduce it by copying/compiling :) – sehe Mar 28 '14 at 10:27

1 Answers1

1

Let me do your work for you show you how I'd analyze this problem:

#include <boost/regex.hpp>
#include <boost/cregex.hpp>
#include <vector>

int main()
{
    using namespace boost;

    regex re(".*");

    const std::vector<char> chunkData;

    cregex_iterator reIteratorEnd;
    cregex_iterator reIterator(
            reinterpret_cast<const char*>(chunkData.data()),
            reinterpret_cast<const char*>(chunkData.data()) + chunkData.size(),
            re); // Here the search is being done...}
}

This compiles just fine for me. And there's nothing else given in your question that we can actually reproduce.

You can take it from there. See when it starts to fail. 90% of the time, it will then be obvious why it fails. Otherwise, come back with the clearer, better question.

PS.

  1. I'm aware of the fact that this is technically not an answer. I think it's helping nonetheless (and it doesn't quite fit in a comment)
  2. You of course don't need the re-interpret cast here in my SSCCE. I'm assuming your chunkData might be (who knows) actually a std::deque<unsigned char> or similar? In such a case, see whether you should use a static_cast: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? and Regular cast vs. static_cast vs. dynamic_cast
Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633