... I think the perl code actually compiles (err, runs) though. :-)
// A. Using a struct. The old manual way.
struct my_lambda {
my_lambda(int c) : c_(c) {}
int operator() (int x) const {
return x == c_;
}
int c_;
};
auto f(vector<int> numbers) {
my_lambda lam(2);
// remove all the matching elements
erase_if(numbers, lam);
return numbers;
}
// B. Using a lambda
auto g(vector<int> numbers) {
int c = 2;
erase_if(numbers, [c](int x) { return x == c; });
return numbers;
} auto operator "" _r(char const* str, unsigned long) {
return std::regex{str};
}
To avoid all the backslashes, you can use a raw string literal: int main() {
auto myre = R"(^hello\w*)"_r;
} void foo(const int* const p1, int* const p2) {
int a = *p1;
*p2 += 42;
int b = *p1;
return a == b; // b = a + 42
}
int main() {
int x = 0;
return foo(&x, &x);
} const int* const
instead of const int*