Boost的数据驱动测试'联接运算符`+`破坏了第一列 [英] Boost's data-driven tests' join operator `+` corrupts first column
本文介绍了Boost的数据驱动测试'联接运算符`+`破坏了第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
BOOST_DATA_TEST_CASE(
sampleTest,
(data::make(1) ^ data::make(2)) + (data::make(3) ^ data::make(4)),
var1,
var2)
{
std::cout << var1 << "," << var2 << std::endl;
}
我期望的输出是:
1,2
3,4
但是,var1
似乎已损坏:
$> ./MyTests --run_test=Tests/sampleTest
Running 2 test cases...
202875304,2
202875304,4
*** No errors detected
$> ./MyTests --run_test=Tests/sampleTest
Running 2 test cases...
83976616,2
83976616,4
*** No errors detected
我做错什么了吗?
推荐答案
那是一个错误.长话短说:请向图书馆维护者报告.
That's a bug. Long story short: please report it to the library maintainers.
实际上,zip
操作返回一个元组std::tuple<int const&, int const&>
:
Indeed, the zip
operation returns a tuple std::tuple<int const&, int const&>
:
尽管当时数据集本身还处于活动状态,但是在join
操作中通过引用返回了元组...:
and though the dataset itself is properly alive at the time, the tuple is returned by reference in the join
operation...:
sample const& operator*() const { return m_first_size > 0 ? *m_it1 : *m_it2; }
The proper fix would be to extend the dataset concept to not only have a ::sample
type¹ but also a ::reference
type. That's quite an invasive change.
¹奇怪的是目前没有记载
¹ strangely not documented at this time
这篇关于Boost的数据驱动测试'联接运算符`+`破坏了第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文