std::sort functor one line
问题 I have declared a functor and made a call so std::sort with that functor as a parameter. Code: struct { bool operator() (const CString& item1, const CString& item2){ return MyClass::Compare( Order(_T("DESC")), item1, item2); } }Comparer; std::sort(AllObjects.GetData(), AllObjects.GetData() + AllObjects.GetSize(), Comparer); Simple question: can I do this in one line? 回答1: If your compiler supports c++11, you can use a lambda std::sort(AllObjects.GetData(), AllObjects.GetData() + AllObjects