#include<vector>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
template <typename T>
void show( const T& a){
for(auto p = a.begin(); p != a.end(); p ++)
cout << *p << endl;
cout << endl;
}
int main(){
vector <string> a;
a.push_back( "ACM");
a.push_back( "acm");
a.push_back( "Bin");
a.push_back( "Joey");
sort( a.begin(), a.end());
show( a);
//二元谓词对应的lambda表达式 (每用一次,得再写一次;没有函数对象更通用)
sort( a.begin(), a.end(), []( string a, string b){
string s1( a), s2( b);
transform( s1.begin(), s1.end(), s1.begin(), ::tolower);
transform( s2.begin(), s2.end(), s2.begin(), ::tolower);
return ( s1 < s2);
});
show( a);
}
C++ 二元谓词对应的lambda表达式
最新推荐文章于 2022-07-12 15:50:10 发布