0
我正在寻找检查两个向量交叉点的最佳方法。Boost.Test - 如何检查交叉点上的两个向量?
像
for (auto const & first: first_vector)
for (auto const & next: next_vector)
if first == next
return false;
嵌套循环可以做的工作,但它看起来并不像一个如Boost.Test十岁上下的方式。无论看看Boost.Test有很大帮助,作为唯一的测试用例预定义是BOOST_CHECK_EQUAL_COLLECTIONS
更新
BOOST_FIXTURE_TEST_CASE(paths,fixture_t)
{
for(int i=0,j=vids.size(); i!=j; i++)
{
for(int p=0,q=vids.size(); p!=q; p++)
{
if (i == p)
{
continue;
}
if (i < p)
{
BOOST_TEST_CONTEXT("Equal match at positions " << i << " and " << p)
BOOST_TEST(vids[i] != vids[p]);
}
}
}
}
['std :: set_intersection'](http://en.cppreference.com/w/cpp/algorithm/set_intersection)? – NathanOliver
性能取决于两个矢量的大小。如果'std :: set_intersection'不够好,你需要解释原因。提示:如果两个矢量都很大,你可以用其中一个来制作BST,这将显着加快速度。 – erip
'std :: set_intersection'很好,但是如何以'BOOST_CHECK_EQUAL_COLLECTIONS'这样的方式从'Boost.Test'中获取相应的答案(值和确切位置)? – user1587451