This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
int main() { | |
std::string s = "xAAAyyByABCxGxZyIxGyyZI"; | |
std::cout << "Before: '" << s << "'" << std::endl; | |
bool (*pred1)(char) = [](char c) { return c == 'x' || c == 'y'; }; | |
std::replace_if(s.begin(),s.end(),pred1,'*'); | |
std::cout << "1st tr: '" << s << "'" << std::endl; | |
auto pred2 = [](char c) { return c == '*'; }; | |
std::replace_if(s.begin(),s.end(),pred2,'#'); | |
std::cout << "2nd tr: '" << s << "'" << std::endl; | |
return 0; | |
} |
pred2 demonstrates how to shorten the lengthy type declaration.