簡體   English   中英

為什么TBB無法將`int`轉換為`const tbb :: atomic <unsigned int> &`,但std :: atomic可以嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM