|
Boost Users : |
Subject: Re: [Boost-users] [BGL] vis passed by value to depth_first_visit
From: Shaun Jackman (sjackman_at_[hidden])
Date: 2011-04-20 15:40:05
On Wed, 2011-04-20 at 10:13 -0700, Jeremiah Willcock wrote:
> On Tue, 19 Apr 2011, Shaun Jackman wrote:
>
> > Hi,
> >
> > I recently learned the hard way that the visitor parameter, vis, is
> > passed by value to depth_first_visit, but passed by reference to
> > detail::depth_first_visit_impl.
> >
> > I was writing a function that implemented depth_first_search, but starts
> > each of the visits at vertices with indegree == 0. If my
> > depth_first_search replacement calls boost::depth_first_visit, each call
> > to depth_first_visit makes a copy of the output iterator, which doesn't
> > work for an output iterator with any state (such as a pointer).
> >
> > Calling an internal boost function like detail::depth_first_visit_impl
> > doesn't seem like a good plan. How should I solve this?
> >
> > My short-term work around is to use an output iterator that does not
> > have any state, such as a back_inserter.
>
> Does passing in boost::ref(vis) work? Otherwise, have your visitor keep a
> reference to the state that should be modified outside the visitor
> (copying a reference just leads to another reference to the same object).
>
> -- Jeremiah Willcock
Hi Jeremiah,
Using boost:ref does not seem to work. It gives the error:
../../boost/graph/depth_first_search.hpp:311:
error: 'class boost::reference_wrapper<TopoVisitor<...> >' has no member named 'start_vertex'
(where the elision ... is my own)
The expression vis.start_vertex(u) does not seem to be valid when vis is
a reference_wrapper. Can boost:ref be coerced to work in this situation?
Thanks,
Shaun
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