私はアプリケーションのboostとstandardからunordered_setを使用しようとしていますが、目的は場所、つまりこのセットの特定の要素のインデックスを見つけることです。結果には微妙な違いがあります。ブースト中の要素はこの簡単なプログラムに従って逆転されます。問題はどこだ?boostと標準のunordered_setの相違
シンプル 'のwhat-if' コード:ブースト
#include <iostream>
#include <iterator>
#include <unordered_set>
#include <boost/unordered_set.hpp>
//using boost::unordered_set;
using std::unordered_set;
using std::distance;
int main()
{
unordered_set<int> Set;
int sz = 10;
for(int k=0;k<sz;k++)
Set.insert(k);
unordered_set<int>::iterator ind_searched = Set.find(8);
unordered_set<int>::size_type indx = distance(Set.begin(),
ind_searched);
std::cout << " Index of element is "
<< indx << std::endl;
return 0;
}
私は
Index of element is 1
を取得し、標準unordered_setと私は
との両方をコンパイルIndex of element is 8
を取得しています
g++ sgi_stl_1.cc -I /home/utab/external_libraries/boost_1_48_0/ -std=c++0x
接頭辞 'unordered'は実際には理由のために存在します。それらのコンテナの順序は定義されておらず、あなたはそれに依存するべきではありません。 – pmr