Design
##Design TheThe problem is that there can only be one vertext with a particular value. Well actually you can add the same value multiple times BUT any operation will be applied to the first vertex with that value, so its like there is only one visible value in the vertex list.
Code Review
##Code Review YesYes you need to store them as pointers (non owning).
##Design The problem is that there can only be one vertext with a particular value. Well actually you can add the same value multiple times BUT any operation will be applied to the first vertex with that value, so its like there is only one visible value in the vertex list.
##Code Review Yes you need to store them as pointers (non owning).
Design
The problem is that there can only be one vertext with a particular value. Well actually you can add the same value multiple times BUT any operation will be applied to the first vertex with that value, so its like there is only one visible value in the vertex list.
Code Review
Yes you need to store them as pointers (non owning).
auto end = std::removeremove_if(std::begin(graph_), std::end(graph_), [&value](Vertex* it){return it->value == value;});
for(auto loop = end; loop != std::end(graph_); ++loop) {
delete *loop;
}
graph_.erase(end, std::end(graph_));
auto end = std::remove(std::begin(graph_), std::end(graph_));
for(auto loop = end; loop != std::end(graph_); ++loop) {
delete *loop;
}
graph_.erase(end, std::end(graph_));
auto end = std::remove_if(std::begin(graph_), std::end(graph_), [&value](Vertex* it){return it->value == value;});
for(auto loop = end; loop != std::end(graph_); ++loop) {
delete *loop;
}
graph_.erase(end, std::end(graph_));
for (auto it = graph_.begin(); it != graph_.end(); ++it)
{
if ((*it)->value() == value)
{
delete *it;
graph_.erase(it);
return;
}
}
There is a pattern for this: Erase Remove Idiom.
auto end = std::remove(std::begin(graph_), std::end(graph_));
for(auto loop = end; loop != std::end(graph_); ++loop) {
delete *loop;
}
graph_.erase(end, std::end(graph_));
for (auto it = graph_.begin(); it != graph_.end(); ++it)
{
if ((*it)->value() == value)
{
delete *it;
graph_.erase(it);
return;
}
}
There is a pattern for this: Erase Remove Idiom.
auto end = std::remove(std::begin(graph_), std::end(graph_));
for(auto loop = end; loop != std::end(graph_); ++loop) {
delete *loop;
}
graph_.erase(end, std::end(graph_));