I'm just messing around with some lambda expressions and I decided to attempt to remove duplicate elements from a vector. However, it isn't working. I put in some debug logging and it appears that std::count isn't returning the expected result. Any would would be greatly appreciated.
For reference, I know this isn't the most efficient way to remove an item from a vector! I was just experimenting with lambdas as I don't understand them as well as I would like to.
Thanks!
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
std::vector<int> v = { 0, 0, 1, 2, 4, 4, 4 };
std::remove_if(v.begin(), v.end(), [&v](const int &x)
{
return std::count(v.begin(), v.end(), x) > 1;
});
std::cout << "\n\nResult:\n";
for (const auto& i : v) { std::cout << i << std::endl; }
return 0;
}