c++ - Why is Boost Graph Library's `source()` a global function? -
i understand in generic programming, algorithms decoupled containers. make no sense implement generic algorithm instance method (the same algorithm should work on multiple concrete classes; don't want make them inherit 1 abc since exponentially increase number of classes).
but in case of source()
function in boost graph library, don't understand why global function , not instance method of graph class.
as far tell reading bgl source code, source(e, g)
needs know implementation details of graph , edge objects passed it; it's not enough know interfaces.
so source()
not generic algorithm. in other words, needs know concrete class of graph instance. why not put in same class instance method? wouldn't lot cleaner / less confusing making global function needs customized each class it's called upon?
update
the relevant source code:
// dwa 09/25/00 - needed more explicit reverse_graph work. template <class directed, class vertex, class outedgelists, class vertexlists, class directeds, class vertexproperty, class edgeproperty, class graphproperty, class edgelists> inline vertex source(const detail::edge_base<directed,vertex>& e, const adjacency_list<outedgelists, vertexlists, directeds, vertexproperty, edgeproperty, graphproperty, edgelists>&) { return e.m_source; } namespace boost { namespace detail { template <typename directed, typename vertex> struct edge_base { inline edge_base() {} inline edge_base(vertex s, vertex d) : m_source(s), m_target(d) { } vertex m_source; vertex m_target; }; } }
the source(e, g)
not generic algorithm. part of interface, called concept in c++. reason being non-member function can implemented non-intrusively.
say, instance, wanted std::multimap
implement incidencegraph
concept. if graph library required source()
member function out of luck, since std::multimap
doesn't provide one.
Comments
Post a Comment