gpt4 book ai didi

c++ - boost::sregex_iterator 编译错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:37:10 28 4
gpt4 key购买 nike

我正在尝试使用 boost::cregexp_iterator,如 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...

所有其他代码都被注释掉了。我收到以下错误:

               ^
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)

什么问题?

更新:问题出在标志 --std=c++11 - 我正在针对此问题发布另一篇文章。UPDATE2:问题是我使用的是旧版本的 boost (1.4.3),移动到最新版本解决了它

最佳答案

让我 为你做你的工作 向你展示我将如何分析这个问题:

#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...}
}

compiles just fine for me .您的问题中没有任何else我们可以实际重现。

你可以从那里拿走它。看看它什么时候开始失败。 90% 的时候,失败的原因就会很明显。否则,请提出更清晰、更好的问题。

附言。

  1. 我知道这在技术上不是答案。我认为它仍然有帮助(并且不太适合评论)
  2. 您当然不需要在我的 SSCCE 中重新解释类型转换。我假设你是 chunkData可能(谁知道)实际上是 std::deque<unsigned char>或类似的?在这种情况下,看看你是否应该使用 static_cast : When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?Regular cast vs. static_cast vs. dynamic_cast

关于c++ - boost::sregex_iterator 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700930/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com