Boost logo

Boost Users :

From: mycia (yg-boost-users_at_[hidden])
Date: 2002-11-08 13:33:42


to Boost Graph Library designers:

in the boost/graph/graph_traits.hpp (line 104):

//--begin----------------------------------------------------------------
// Since pair is in namespace std, Koenig lookup will find source and
// target if they are also defined in namespace std. This is illegal,
// but the alternative is to put source and target in the global
// namespace which causes name conflicts with other libraries (like
// SUIF).
namespace std {
  template <class T, class G>
  T source(pair<T,T> p, const G&) { return p.first; }

  template <class T, class G>
  T target(pair<T,T> p, const G&) { return p.second; }
}
//--end----------------------------------------------------------------

why not change it with:

//--begin----------------------------------------------------------------
  template <class E, class G>
  typename boost::graph_traits<G>::vertex_descriptor
  source(E e, const G& g) { return boost::source(e,g); }

  template <class E, class G>
  typename boost::graph_traits<G>::vertex_descriptor
  target(E e, const G& g) { return boost::target(e,g); }

//--end----------------------------------------------------------------

and add the following in boost/graph/vector_as_graph.hpp

//--begin----------------------------------------------------------------
  template <class T, class EdgeList, class Alloc>
  T source(std::pair<T,T> p, const std::vector<EdgeList, Alloc>&) { return
p.first; }

  template <class T, class EdgeList, class Alloc>
  T target(std::pair<T,T> p, const std::vector<EdgeList, Alloc>&) { return
p.second; }
//---end---------------------------------------------------------------

which means, vector_as_graph handles source() and target() inside its class
(and in boost namespace)
and makes std::source() and std::target() more general

the reason why I want to modify this is that
the original design makes trouble when I try to develop a subgraph view
adaptor (something like filtered_graph, but accept vector_as_graph type)
I need to define my own source() and target() to deal with my own subgraph
view class, as shown below:

namespace boost {
  template <class G>
    typename subview_graph<G>::vertex_descriptor
    target(typename subview_graph<G>::edge_descriptor e, subview_graph<G>&
v)
    {...}
}

however, when dealing with vector_as_graph (which means the 1st argument,
edge_descriptor, will be std::pair<int,int>),
the compiler complains ambiguity between std::target() and boost::target()

in fact, it will make trouble to everyone who wants to define his/her own
source() & target() function but the 1st argument is std::pair<T,T>

if it's possible, please fix this strange design
or any other opinions will be appreciated

best regards,

hcyeh


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net