#include <stack>
#include <list>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
void biggies(vector<string>& str,vector<string>::size_type sz)
{
sort(str.begin(),str.end());
auto end_unique=unique(str.begin(), str.end());
str.erase(end_unique,str.end());
//When I remove the "const" in the parameter list, the code can't compile
stable_sort(str.begin(), str.end(), [](const string&a,const string&b){return a.size()<b.size();});
auto wc=find_if(str.begin(), str.end(), [sz](string& a){return a.size()>=sz;});
for_each(wc, str.end(), [](string& s){cout<<s<<endl;});
}
int main()
{
vector<string>vec{"11","22","1","1111","2222","2","111","222"};
biggies(vec, 2);
}
I test the code in Xcode 6.4 and Visual Studio 2015 and it turns out that both cannot compile without the "const" in the parameter list. I wonder why the lack of "const" would disrupt the compilation? I'll be very thankful with your answers.