/* * Standard containers, std::vector, exercise 5. * * Note: ::tolower, where :: is required to disambiguate, since tolower is also * the name of a template function (). If that had not been possible, * wrapping the call in a function would have solved the problem, e.g. in a * lambda expression: * * transform(begin(s), end(s), begin(s), [](char c){ return tolower(c); }); */ #include #include #include #include #include #include using namespace std; struct lower_case { string operator()(string s) const { transform(s.begin(), s.end(), s.begin(), ::tolower); return s; } typedef string return_type; typedef string first_argument_type; typedef string second_argument_type; }; int main() { vector cars{ istream_iterator(cin), istream_iterator() }; sort(begin(cars), end(cars)); transform(begin(cars), end(cars), begin(cars), lower_case()); copy(begin(cars), end(cars), ostream_iterator(cout, "\n")); return 0; }