Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Is adjacency_iterator not Equality Comparable?
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-05-19 12:52:43


> Please find a minimalist (but different) example in the attachments. I
> currently do know what's wrong but it's probably still better for my
> next question to attach the file. Consider the following line in my
> attached code:
>
> iterator pos = find(begin, end, "3");
>
> I know that this line doesn't compile because the value type of vertex
> iterator is not necessarily the same as VertexProperties. But, then, is
> there a simple way to find the vertex iterator that points to "3"? (I
> mean something as succinct as the above line of code. I DO already know
> that it's possible to pass an ugly function object to help find(). But,
> that's far too ugly.)

What about this (not tested)?

typedef property<graph_type, vertex_bundle_t>::const_type pm_type;
pm_type props(get(vertex_bundle, g));
typedef graph_traits<graph_type>::vertex_iterator v_iter_type;
std::pair<v_iter_type, v_iter_type> verts(vertices(g));
typedef property_map_iterator_generator<pm_type, v_iter_type>::type
   iter_type;
iter_type pos = find(make_property_map_iterator(props, verts.first),
                      make_property_map_iterator(props, verts.second),
                      "3");
v_iter_type pos_v = pos.base();
vertex_descriptor v = *pos_v;

This needs <boost/property_map/property_map_iterator.hpp> to be included,
plus all of the usual graph stuff.

-- Jeremiah Willcock


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