完全なコードはhttps://gist.github.com/1341623にあります
配列が他のベクトルのインデックスによって順序付けられるように、別のベクトルのインデックス配列(またはベクトル)を並べ替えたいと思います。ただし、vector::atのタイプは解決できません。
私は次のように試しました:
これで結構です
sort(v.begin(), v.end());
配列に従ってインデックスを並べ替えたいのですが、プレースホルダーはoperator[]をオーバーロードしません
sort(index,index+10, a[_1] < a[_2]);
ただし、operator+とoperator*をオーバーロードします
sort(index,index+10, *(a+_1) < *(a+_2));
ベクトルに従ってインデックスをソートしたいのですが、コンパイラは `vector ::at'のタイプを解決できません。
sort(index,index+10,
bind(&(vector<int>::at), &v, _1) < bind(&(vector<int>::at), &v, _2));
// error: no matching function for call
// to ‘bind(<unresolved overloaded function type>, ...
Webで検索したところ、オーバーロードされたメソッドタイプを指定する必要があることがわかりましたが、コンパイラはそれでもタイプを解決できないと言っています。
sort(index,index+10,
bind(&static_cast<const int (*)(size_t)>(vector<int>::at), &v, _1)
< bind(&static_cast<const int (*)(size_t)>(vector<int>::at), &v, _2));
// error: invalid static_cast from type ‘<unresolved overloaded function type>’
// to type ‘const int (*)(size_t)’ ...
vector :: atのバージョンを取得しようとしましたが、変換に失敗したようです。
vector<int>::const_reference (*vector_int_at)(vector<int>::size_type)(vector<int>::at);
sort(index,index+10,
bind(&vector_int_at, &v, _1) < bind(&vector_int_at, &v, _2));
// error: no matches converting function ‘at’ to type ‘const int& (*)(size_t)’ ...
この問題に対して何ができますか?または私は何かを誤解していますか?