0

host_vector でソートしたいオブジェクトがいくつかあります。これらのオブジェクトには、オブジェクトの Id (整数) を比較する < 演算子が定義されています。ベクトルには、オブジェクトへのポインターが含まれます。

ベクトルを実行thrust::sort(object_vector.begin(),object_vector.end());して反復処理して Id を出力すると、次のようになります。
48, 49, 0, 1, [..], 47, 50, [..]

実行するstd::sort(object_vector.begin(),object_vector.end()); と、ID が順番に取得されます。これら 2 つの値が順不同である理由がわかりません (同じ数のオブジェクトに対して常に同じです)。
この 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;)
4

1 に答える 1