Here's a C++ 0x version, using a lambda function:<p><pre><code> #include <iostream>
#include <algorithm>
int main(int argc, char** argv) {
int src[] = { 1, 2, 3, 4 };
int* end = std::remove_if(src, src + sizeof(src) / sizeof(int),
[](int i) -> bool { return i % 2 != 0; });
for (int* p = src; p != end; ++p)
std::cout << *p << " ";
std::cout << std::endl;
}
</code></pre>
I wasn't sure about the lambda function syntax, but this compiles with g++ 4.5 (interestingly, even with the -Wall option, g++ doesn't warn about main not returning a value). Shows that even c++ can be shorter than java...