unique push to vector

for/release
Denes Matetelki 12 years ago
parent c6f9a544e3
commit f0710ec710

@ -3,13 +3,12 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <set>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
// directed, weighted
/// @todo weight type as param too?
template <typename V, template <typename V,
typename E = int> typename E = int>
class Graph { class Graph {
@ -486,9 +485,11 @@ std::vector<typename Graph<V, E>::pointer> Graph<V, E>::neighboursOf(const_refer
if (vertex_it == m_vertices.end()) if (vertex_it == m_vertices.end())
return retval; return retval;
std::set<pointer> tmp;
std::for_each((*vertex_it).m_edges.begin(), (*vertex_it).m_edges.end(), std::for_each((*vertex_it).m_edges.begin(), (*vertex_it).m_edges.end(),
[&retval](const EdgeTo& e) [&tmp, &retval](const EdgeTo& e)
{ retval.push_back(e.m_destination); }); /// @todo unique push! { if (tmp.insert(e.m_destination).second)
retval.push_back(e.m_destination); });
return retval; return retval;
} }

Loading…
Cancel
Save