I tried to make a real one liner:
std::stable_partition(std::begin(input), std::end(input), [&input](int const& a){return 0==((&a-&input[0])%2);});
And here is the complete program:
#include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> input {0,1,2,10,11}; std::stable_partition(std::begin(input), std::end(input), [&input](int const& a){return 0==((&a-&input[0])%2);}); for (auto v : input) std::cout << v << " "; }
Well, I know, it works only for the reason that the vector uses an adjacent array of elements, and all this is dirty ... But for this there is one liner specified by OP, and it does not require anything superfluous, how to increase ...
source share