std::set_difference 中使用的 std:vector 中的断言错误

发布于 2024-07-13 22:42:23 字数 604 浏览 3 评论 0原文

我试图找到两个向量的集合差,所以我做了这样的事情:

std::vector<sha1_hash> first_vec, second_vec, difference_vec;

// populate first_vec and second_vec ...

std::sort(first_vec.begin(),first_vec.end());
std::sort(second_vec.begin(),second_vec.end());

std::set_difference(first_vec.begin(),first_vec.end(),
            second_vec.begin(),second_vec.end(),
            difference_vec.begin());

当我在调试中运行它时,我得到以下运行时断言失败(在“向量”中):

_SCL_SECURE_VALIDATE_RANGE(_Myptr < ((_Myvec *)(this->_Getmycont()))->_Mylast);

我正在使用 VS 2008。 关于什么可以触发这个的任何想法?

I am trying to find the set difference of two vectors, so i do something like this:

std::vector<sha1_hash> first_vec, second_vec, difference_vec;

// populate first_vec and second_vec ...

std::sort(first_vec.begin(),first_vec.end());
std::sort(second_vec.begin(),second_vec.end());

std::set_difference(first_vec.begin(),first_vec.end(),
            second_vec.begin(),second_vec.end(),
            difference_vec.begin());

When i run this in debug, i get the following run-time assertion failure (in 'vector'):

_SCL_SECURE_VALIDATE_RANGE(_Myptr < ((_Myvec *)(this->_Getmycont()))->_Mylast);

I am using VS 2008.
Any ideas on what can trigger this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静待花开 2024-07-20 22:42:23

与大多数 C++ 算法一样,set_difference 不会在输出向量中创建以前不存在的新条目。 您需要在输出中创建空间来保存结果。

编辑:或者使用插入迭代器(以下未经测试):

 back_insert_iterator< std::vector<sha1_hash> > bi( difference_vec ); 

std::set_difference(first_vec.begin(),first_vec.end(),
            second_vec.begin(),second_vec.end(),
            bi);

Like most c++ algorithms, set_difference does not create new entries in the output vector where none existed before. You ned to create space in the output to hold the results.

Edit: Or use an an insert iterator (following untested):

 back_insert_iterator< std::vector<sha1_hash> > bi( difference_vec ); 

std::set_difference(first_vec.begin(),first_vec.end(),
            second_vec.begin(),second_vec.end(),
            bi);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文