小编Jer*_*ing的帖子

将boost :: unordered_set作为结果映射传递给boost :: split

有没有人知道如果将boost :: unordered_set作为boost :: split的第一个参数传递是犹太洁食?在libboost1.42-dev下,这似乎会导致问题.这是一个导致问题的小例子程序,称之为test-split.cc:

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/unordered_set.hpp>
#include <string>

int main(int argc, char **argv) {
  boost::unordered_set<std::string> tags_set;
  boost::split(tags_set, "a^b^c^",
               boost::is_any_of(std::string(1, '^')));
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后,如果我运行以下命令:

g++ -o test-split test-split.cc; valgrind ./test-split
Run Code Online (Sandbox Code Playgroud)

我在valgrind中得到了一堆投诉,就像下面那样(我有时也看到没有valgrind的coredump,虽然它似乎根据时间而变化):

==16843== Invalid read of size 8
==16843==    at 0x4ED07D3: std::string::end() const (in /usr/lib/libstdc++.so.6.0.13)
==16843==    by 0x401EE2: unsigned long boost::hash_value<char, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /tmp/test-split)
...
==16843==    by 0x402248: boost::unordered_set<std::string, boost::hash<std::string>, std::equal_to<std::string>, std::allocator<std::string> >& boost::algorithm::split<boost::unordered_set<std::string, boost::hash<std::string>, std::equal_to<std::string>, std::allocator<std::string> >, char const [26], …
Run Code Online (Sandbox Code Playgroud)

c++ boost split unordered-set c++11

5
推荐指数
1
解决办法
1187
查看次数

标签 统计

boost ×1

c++ ×1

c++11 ×1

split ×1

unordered-set ×1