Boost logo

Boost Users :

From: Aaron Windsor (aaron.windsor_at_[hidden])
Date: 2007-04-20 06:46:59


On 4/20/07, Dima F. <quantera_at_[hidden]> wrote:
> Aaron Windsor wrote:
>
> > Your predicate should have const member functions - replace
> >
> > bool operator()(const vertex_t &v) {}
> >
> > bool operator()(const edge_t &e) {}
> >
> > with
> > bool operator()(const vertex_t &v) const {}
> >
> > bool operator()(const edge_t &e) const {}
> >
> > and it should compile.
>
> Thanks, it indeed compiles fine.
>
> Is there are other restrictions on using filtered_graph with
> breadth_first_search? The problem is that predicates of a filtered_graph
> should be Default Constructable, and it seems that even though in an
> example in a documentation of filtered_graph predicate has instance
> members, predicates of filtered_graphs which are used in breadth_first_search
> couldn't have any non-static members, because at some stage during the
> search predicates are default-constructed, and values of it's members
> are lost - for example, in order to be able to implement my idea of an
> induced subgraph, I would like each predicate instance to have a pointer
> to a graph to which filtering is going to be applied (see an example below).
>
> Is it somehow possible to let predicates to a filtered_graph have
> instance variables? Of course it is possible to use globals or static
> members, but this is a bad solution.

Hi Dima,

The predicates used in a filtered_graph can have non-static members.
In particular, I don't see anything wrong with the example you included
in your previous email. The predicate needs to be default constructable
because in the implementation of filtered_graph, it's stored by value in
an iterator and the iterator must be default constructable. But you can
still create a non-default instance of your predicate and pass it in to
filtered_graph and you should get the results you expect - just make
sure it has the correct semantics when default constructed.

Regards,
Aaron


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