Skip to content

Instantly share code, notes, and snippets.

@makulik
Last active December 18, 2020 17:42
C++11 lambda predicate syntax sample
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment