I have searched stackoverflow and found a partial answer to my question already: How to remove elements from a vector based on a condition in another vector? In my case I have two vectors, one containing integers and one containing shared pointers (std::shared_ptr< someType >) and I am not able to figure the pointer arithmetic out the get the code working.
class someAbstractClass
{
};
class someClass : public someAbstractClass
{
};
std::vector<int> condition;
std::vector<std::shared_ptr< someAbstractClass >> container;
condition.push_back(0);
condition.push_back(1);
condition.push_back(0);
container.push_back( std::make_shared< someClass > );
container.push_back( std::make_shared< someClass > );
container.push_back( std::make_shared< someClass > );
std::erase( std::remove_if( container.begin(), conatiner.end(),
[&] ( const std::shared_ptr< someAbstractClass > &s )
{
return condition[ &s - &(*container.begin()) ] == 1;
} ), container.end() );
Is there a way to make this work?