Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

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).

added 7 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
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_));
added 485 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

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_));
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /