diff --git a/lib/graph/graph.hpp b/lib/graph/graph.hpp index 5d02134..2d79c47 100644 --- a/lib/graph/graph.hpp +++ b/lib/graph/graph.hpp @@ -51,7 +51,7 @@ private: struct Vertex { - // bevause of parallell accumulate, ctor(int) is needed and that could conflict + // because of parallell accumulate, ctor(int) is needed and that could conflict // Vertex(const_reference data) : m_data(data), m_edges() {} Vertex() : m_data(), m_edges() {} @@ -270,8 +270,7 @@ bool Graph::edge_iterator::operator==(const_reference_self_type o) const if ( this_is_at_end && other_is_at_end ) return true; if ( this_is_at_end != other_is_at_end ) return false; - return *m_vertex_it == *(o.m_vertex_it) && - *m_edge_it == *(o.m_edge_it); + return *m_vertex_it == *(o.m_vertex_it) && *m_edge_it == *(o.m_edge_it); } template @@ -391,11 +390,9 @@ template inline std::vector::Edge> Graph::Vertex::edges() const { std::vector::Edge> retval; + for (const EdgeTo& e : m_edges) + retval.push_back(Edge(m_data, (e.m_destination)->m_data, e.m_weight)); - /// @todo rewrite for_each to parallel aware - std::for_each(m_edges.begin(), m_edges.end(), - [this, &retval](const EdgeTo& e) - { retval.push_back(Edge(m_data, (e.m_destination)->m_data, e.m_weight)); }); return retval; } @@ -406,16 +403,16 @@ template Graph::Graph(std::initializer_list vertex_list) : Graph() { - std::for_each(vertex_list.begin(), vertex_list.end(), - [this](const_reference v) { addVertex(v); } ); + for(const V& v : vertex_list) + addVertex(v); } template Graph::Graph(std::initializer_list edge_list) : Graph() { - std::for_each(edge_list.begin(), edge_list.end(), - [this](const Edge& e) { addEdge(e.source, e.destination, e.weight); } ); + for (const Edge& e : edge_list ) + addEdge(e.source, e.destination, e.weight); } template @@ -502,10 +499,9 @@ template inline std::vector::value_type> Graph::vertices() const { std::vector retval; - /// @todo rewrite for_each to parallel aware - std::for_each(m_vertices.begin(), m_vertices.end(), - [&retval](const Vertex& v) - { retval.push_back(v.m_data); }); + for (const Vertex& v : m_vertices) + retval.push_back(v.m_data); + return retval; } @@ -518,11 +514,9 @@ std::vector::value_type> Graph::neighboursOf(const_re return retval; std::set tmp; - /// @todo rewrite for_each to parallel aware - std::for_each(vertex_it->m_edges.begin(), vertex_it->m_edges.end(), - [&data, &tmp, &retval](const EdgeTo& e) - { if (tmp.insert(e.m_destination).second) - retval.push_back((e.m_destination)->m_data); }); + for (const EdgeTo& e : vertex_it->m_edges) + if (tmp.insert(e.m_destination).second) + retval.push_back((e.m_destination)->m_data); return retval; } @@ -538,11 +532,9 @@ std::vector Graph::weights(const_reference source, const_reference dest if (find(destination) == m_vertices.end()) return retval; - /// @todo rewrite for_each to parallel aware - std::for_each(vertex_it->m_edges.begin(), vertex_it->m_edges.end(), - [&retval, &destination](const EdgeTo& e) - { if (e.m_destination->m_data == destination) - retval.push_back(e.m_weight); }); + for (const EdgeTo& e : vertex_it->m_edges) + if (e.m_destination->m_data == destination) + retval.push_back(e.m_weight); return retval; } @@ -551,13 +543,10 @@ template inline std::vector::Edge> Graph::edges() const { std::vector::Edge> retval; - - /// @todo rewrite for_each to parallel aware - std::for_each(m_vertices.begin(), m_vertices.end(), - [&retval](const Vertex& v) - { const std::vector e = v.edges(); - retval.insert(retval.end(), e.begin(), e.end()); - }); + for (const Vertex& v : m_vertices) { + const std::vector e = v.edges(); + retval.insert(retval.end(), e.begin(), e.end()); + } return retval; }