[英]Why can't TBB cast `int` to `const tbb::atomic<unsigned int>&`, but std::atomic can?
我正在尝试构建一个具有许多依赖项的大型项目。 阻止构建的最后一件事(?)是TBB无法处理将int
强制转换为const tbb::<unsigned int>&
。 令人讨厌的是,使用std::atomic
(特别是const std::atomic<unsigned int>&
)的相同std::atomic
效果很好。 我无法重构代码以使用std
而不是tbb
(它使用tbb
其他功能,这些功能不属于std
)。
我创建了以下简单的测试用例:
#include <tbb/atomic.h>
#include <atomic>
void good(const std::atomic<unsigned int>& i) {
}
void bad(const tbb::atomic<unsigned int>& i) {
}
int main() {
good(1);
bad(1); // error C2664: 'void bad(const tbb::atomic<unsigned int> &)': cannot convert argument 1 from 'int' to 'const tbb::atomic<unsigned int> &'
}
有谁知道如何解决此问题(不删除对TBB的使用)? 我需要它才能在VS2017中工作。
编辑:另外,我得到以下错误: Error (active) E0415 no suitable constructor exists to convert from "int" to "tbb::atomic<unsigned int>" Testmain.cpp 15
。 因此,大概可以想见,如果有合适的领导者,那么转型将成功。 如何添加一个? 是否对tbb/atomic.h
了编辑以启用此投射?
固定! 问题在于预处理程序定义对于我正在使用的TBB的NuGet发行版已经过时。 VS2017版本15.3.2支持constexpr
,启用__TBB__ATOMIC_CTORS
是必需的。 感谢@StoryTeller为我指出正确的方向。
修复:Git克隆了TBB的最新src并构建。 (有趣的是,C ++中的快捷方式很少是快捷方式)。
从源代码中(我在https://github.com/01org/tbb/blob/tbb_2017/include/tbb/atomic.h中发现我自己没有TBB)我可以看到struct atomic
仅具有一个赋值运算符定义,因此没有非明确的构造函数,这意味着您必须使用tbb::make_atomic
显式构造它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.