|
ついでだから native C++ でも (祭りだ祭りだ)
#if 0 // standard function
bool mycmp(const std::wstring& l, const std::wstring& r) {
return StrCmpLogicalW(l.c_str(), r.c_str())<0;
}
#endif
#if 1 // functional object
struct mycmp {
int factor;
mycmp(int order=1) : factor(order) {}
bool operator()(const std::wstring& l, const std::wstring& r) const {
return (factor*StrCmpLogicalW(l.c_str(), r.c_str()))<0;
}
};
#endif
int main() {
std::vector<std::wstring> tx;
tx.push_back(L"2003-4.txt");
tx.push_back(L"2001-1.txt");
tx.push_back(L"2001-11.txt");
tx.push_back(L"2001-3.txt");
std::sort(tx.begin(), tx.end(), mycmp()); // descending order cmp(-1)
std::copy(tx.begin(), tx.end(), std::ostream_iterator<std::wstring,wchar_t>(std::wcout, L"\n"));
return 0;
}
|