unordered_set, unordered_multiset,unordered_map, unordered_multimap の
要素Tには、std::hash が定義されていることが求められるため、そのままでは
Platform::String^ は unordered_XXX の要素になれない。
# include <unordered_set>
/*
* std::hash<Platoform::String^> を定義する。
* ハッシュ値は Platoform::String::GetHashCode() をそのまま利用できる。
*/
template<> struct std::hash<Platform::String^> {
size_t operator()(Platform::String^ pstr) const {
return static_cast<size_t>(pstr->GetHashCode());
}
};
/* おためし */
# include <iostream>
# include <locale>
# include <string>
using namespace std;
using namespace Platform;
wostream& operator<<(wostream& stream, String^ str) {
return stream << wstring(begin(str), end(str));
}
int main(Array<String^>^ ) {
vector<String^> vps =
{ L"れい", L"いち", L"に", L"さん", L"し",
L"ご", L"ろく", L"しち", L"はち", L"きゅう" };
unordered_set<String^> uss(begin(vps), end(vps));
wcout.imbue(locale("japanese"));
for ( auto item : uss ) {
wcout << item << endl;
}
}