C++相談室 part98
■ このスレッドは過去ログ倉庫に格納されています
0772デフォルトの名無しさん
2012/10/02(火) 20:29:03.13#include <algorithm>
#include <vector>
template <class C, typename T = typename C::value_type>
std::vector<T> copy_to_vec(const C& from) {
std::vector<T> res(from.begin(),from.end());
std::sort(res.begin(),res.end());
return res;
}
int main()
{
std::unordered_map<int,int> from;
from.insert(std::make_pair(1,2));
auto to = copy_to_vec(from);
}
このコードなんですが、unordered_map::value_typeはpair<const key_type,mapped_type>
と勝手にconstが入ってしまうので、sort(...)が使えません。-fpermissibleを入れろと言ってきます。
テンプレート引数でT=...となっている部分を変えて何とかなりませんか?
■ このスレッドは過去ログ倉庫に格納されています