我想要在host_vector上排序一些對象,這些對象有一個<運算符定義,用於比較對象的Id(整數)。該向量包含指向對象的指針。thrust :: sort missorts some values
如果我執行thrust::sort(object_vector.begin(),object_vector.end());
然後通過矢量迭代打印編號的,我得到:
48, 49, 0, 1, [..], 47, 50, [..]
如果我按順序執行std::sort(object_vector.begin(),object_vector.end());
我得到的Id的。我不知道爲什麼這兩個值不合理(它們對於相同數量的對象總是相同的)。
根據這個Id的對象沒有什麼特別的。
stable_sort不會改變任何東西。 使用Id的作品排序矢量。 運營商:
bool operator<(MultiLegBase* other){return (this->getID()<other->getID());}
bool operator==(MultiLegBase* other){return this->getID()==other->getID();}
bool operator>(MultiLegBase* other){return this->getID()>other->getID();}
virtual unsigned int const getID(return m_Id;)
如果你首先創建一個只有整數ID的向量,然後'thrust :: sort'那麼會發生什麼?如果有效,你的'operator''或'operator ='可能有問題。 – Useless
向我們展示您的物體的相關代碼 – Bart
提供完整的重現器。這不應該很難做到。在創建複製器的過程中,您可能會發現問題。 –