Boost logo

Boost Users :

Subject: [Boost-users] [BGL] Getting/deducing type of custom (internal) properties
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2010-11-17 04:53:51


Hi,

this is to substitute the thread: [BGL] Accessing internal properties and
returning a "template"-type

I think I can now deliver even more details on my problem.

Again, I have the following concept:

template < class GRAPH, class EDGE_PREDICATE, class VERTEX_PREDICATE >
class FilteredGraph
{
public:
    
    /// Defines an alias type to represent the filtered_graph
    typedef filtered_graph< GRAPH, EDGE_PREDICATE, VERTEX_PREDICATE >
FilteredGraphContainer;

//
// some c'tors, member functions etc.
//
    template< class VERTEXPROPERTIES >
    VERTEXPROPERTIES& properties(const Vertex& v) const
    {
            typename property_map<FilteredGraphContainer,
vertex_properties_t>::const_type param = get(vertex_properties, graph_);
            return (param[v]);
    }

//
// some more stuff
//

private:
        FilteredGraphContainer graph_;
};

The compiler can't obviously deduce the type of the return-value of
properties( Vertex v) as this type is not specified in the argument list.
This is what I understood so far by finding this:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.4

I have the same properties-function in my Graph-class, which uses custom
properties as in
 http://live.boost.org/doc/libs/1_43_0/libs/graph/doc/using_adjacency_list.html#sec:adjacency-
list-properties

The definition of this class basically is:
enum vertex_properties_t { vertex_properties };
enum edge_properties_t { edge_properties };
namespace boost {
        BOOST_INSTALL_PROPERTY(vertex, properties);
        BOOST_INSTALL_PROPERTY(edge, properties);
}

/* the graph base class template */
template < typename VERTEXPROPERTIES, typename EDGEPROPERTIES >
class Graph
{
public:

    /// an adjacency_list like we need it
    typedef adjacency_list<
            setS, // disallow parallel edges
            vecS, // vertex container
            undirectedS, // undirected graph
            property<vertex_properties_t, VERTEXPROPERTIES>,
            property<edge_properties_t, EDGEPROPERTIES>
> GraphContainer;
//
//...
//
private:
        GraphContainer graph_;
};

This is all, more or less, similar to the template-definitions used in the BGL,
or at least that was my intention.

Interestingly, when I have a function:

template< class GRAPH >
void some_function( const GRAPH& g){
GRAPH::Vertex v;
// Get some included vertex out of g and assign it to v;
v = someVertexFromG( g );
filtered_graph< GRAPH, keep_all, keep_all > fg(g, keep_all(), keep_all());
get(vertex_properties, fg, v);
}

it works without any problem.

Now the question, is it possible to solve this issue for FilteredGraph and
keep the same concept as for Graph, or do I need to specify the type of
VERTEXPROPERTIES somewhere _beforehand_ in order to let the compiler get this
type (not preferred, for obvious reasons)?

Best,

Cedric


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