From 955aba40add46110d7e4e3e7250ab3fa09b50921 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Tue, 30 Apr 2013 20:49:18 +0200 Subject: [PATCH] short functions are inline --- graph.hpp | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/graph.hpp b/graph.hpp index 7c24bd8..8728146 100644 --- a/graph.hpp +++ b/graph.hpp @@ -200,21 +200,21 @@ private: // Edge template -Graph::Edge::Edge(pointer source, pointer destination, float weight) +inline Graph::Edge::Edge(pointer source, pointer destination, float weight) : m_source(source) , m_destination(destination) , m_weight(weight) {} template - Graph::Edge::Edge(const Edge& o) +inline Graph::Edge::Edge(const Edge& o) : m_source(o.m_source) , m_destination(o.m_destination) , m_weight(o.m_weight) {} template -void Graph::Edge::swap(Edge& o) +inline void Graph::Edge::swap(Edge& o) { std::swap(m_source, o.m_source); std::swap(m_destination, o.m_destination); @@ -225,7 +225,7 @@ void Graph::Edge::swap(Edge& o) // edge iterator template -Graph::edge_iterator::edge_iterator(const_reference_self_type o) +inline Graph::edge_iterator::edge_iterator(const_reference_self_type o) : m_vertices(o.m_vertices) , m_vertex_it(o.m_vertex_it) , m_edge_it(o.m_edge_it) @@ -245,7 +245,7 @@ bool Graph::edge_iterator::operator==(const_reference_self_type o) const } template -void Graph::edge_iterator::swap(reference_self_type other) +inline void Graph::edge_iterator::swap(reference_self_type other) { std::swap(m_vertices, other.m_vertices); std::swap(m_vertex_it, other.m_vertex_it); @@ -254,7 +254,7 @@ void Graph::edge_iterator::swap(reference_self_type other) } template -Graph::edge_iterator::edge_iterator(std::vector vertices, bool begin) +inline Graph::edge_iterator::edge_iterator(std::vector vertices, bool begin) : m_vertices(vertices), m_vertex_it(), m_edge_it(), m_edge() { if (begin) { @@ -270,7 +270,7 @@ Graph::edge_iterator::edge_iterator(std::vector vertices, bool begin) } template -void Graph::edge_iterator::resetEdge() +inline void Graph::edge_iterator::resetEdge() { if (m_vertex_it == m_vertices.end() || (*m_vertex_it).m_edges.empty()) { m_edge = Edge(); @@ -303,20 +303,20 @@ void Graph::edge_iterator::advance(int n) // EdgeTo template -Graph::EdgeTo::EdgeTo(const_reference destination, float weight) +inline Graph::EdgeTo::EdgeTo(const_reference destination, float weight) : m_destination(const_cast(&destination)) , m_weight(weight) {} template -void Graph::EdgeTo::swap(EdgeTo& o) +inline void Graph::EdgeTo::swap(EdgeTo& o) { std::swap(m_destination, o.m_destination); std::swap(m_vertices, o.m_weight); } template -bool Graph::EdgeTo::operator==(const EdgeTo& other) const +inline bool Graph::EdgeTo::operator==(const EdgeTo& other) const { return m_destination == other.m_destination && m_weight == other.m_weight; @@ -326,7 +326,7 @@ bool Graph::EdgeTo::operator==(const EdgeTo& other) const // Vertex template -bool Graph::Vertex::operator==(const Vertex& other) const +inline bool Graph::Vertex::operator==(const Vertex& other) const { return m_data == other.m_data && m_edges.size() == other.m_edges.size() && @@ -334,13 +334,13 @@ bool Graph::Vertex::operator==(const Vertex& other) const } template -void Graph::Vertex::addEdge(const_reference destination, float weight) +inline void Graph::Vertex::addEdge(const_reference destination, float weight) { m_edges.push_back(EdgeTo(destination, weight)); } template -void Graph::Vertex::removeEdge(const_reference destination, float weight) +inline void Graph::Vertex::removeEdge(const_reference destination, float weight) { m_edges.erase(std::find_if(m_edges.begin(), m_edges.end(), [&destination, &weight](const EdgeTo& e) @@ -349,7 +349,7 @@ void Graph::Vertex::removeEdge(const_reference destination, float weight) } template -void Graph::Vertex::removeAllEdgesTo(const_reference destination) +inline void Graph::Vertex::removeAllEdgesTo(const_reference destination) { std::remove_if(m_edges.begin(), m_edges.end(), [&destination](const EdgeTo& e) @@ -357,7 +357,7 @@ void Graph::Vertex::removeAllEdgesTo(const_reference destination) } template -std::vector::Edge> Graph::Vertex::edges() const +inline std::vector::Edge> Graph::Vertex::edges() const { std::vector::Edge> retval; @@ -372,15 +372,15 @@ std::vector::Edge> Graph::Vertex::edges() const // Graph template -typename Graph::size_type Graph::numberOfEdges() const +inline typename Graph::size_type Graph::numberOfEdges() const { return std::accumulate(m_vertices.begin(), m_vertices.end(), 0, - [](int sum, const Vertex& v) - { return sum + v.m_edges.size(); }); + [](int sum, const Vertex& v) + { return sum + v.m_edges.size(); }); } template -bool Graph::addVertex(const_reference data) +inline bool Graph::addVertex(const_reference data) { if (find(data) != m_vertices.end()) return false; @@ -390,7 +390,7 @@ bool Graph::addVertex(const_reference data) } template -bool Graph::removeVertex(const_reference data) +inline bool Graph::removeVertex(const_reference data) { typename std::vector::iterator it = find(data); if (it == m_vertices.end()) @@ -416,7 +416,7 @@ bool Graph::addEdge(const_reference source, const_reference destination, floa } template -bool Graph::removeEdge(const_reference source, const_reference destination, float weight) +inline bool Graph::removeEdge(const_reference source, const_reference destination, float weight) { typename std::vector::iterator it = find(source); if (it == m_vertices.end()) @@ -427,7 +427,7 @@ bool Graph::removeEdge(const_reference source, const_reference destination, f } template -bool Graph::removeAllEdges(const_reference source, const_reference destination) +inline bool Graph::removeAllEdges(const_reference source, const_reference destination) { typename std::vector::iterator it = find(source); if (it == m_vertices.end()) @@ -438,7 +438,7 @@ bool Graph::removeAllEdges(const_reference source, const_reference destinatio } template -std::vector::pointer> Graph::vertices() const +inline std::vector::pointer> Graph::vertices() const { std::vector retval; std::for_each(m_vertices.begin(), m_vertices.end(), @@ -479,7 +479,7 @@ std::vector Graph::edgesBetween(const_reference source, const_referenc } template -std::vector::Edge> Graph::edges() const +inline std::vector::Edge> Graph::edges() const { std::vector::Edge> retval; @@ -494,7 +494,7 @@ std::vector::Edge> Graph::edges() const template -typename std::vector::Vertex >::const_iterator Graph::find(const_reference data) const +inline typename std::vector::Vertex >::const_iterator Graph::find(const_reference data) const { return std::find_if(m_vertices.begin(), m_vertices.end(), [&data](const Vertex& v) @@ -502,7 +502,7 @@ typename std::vector::Vertex >::const_iterator Graph::find( } template -typename std::vector::Vertex >::iterator Graph::find(const_reference data) +inline typename std::vector::Vertex >::iterator Graph::find(const_reference data) { return std::find_if(m_vertices.begin(), m_vertices.end(), [&data](const Vertex& v)