Boost logo

Boost :

Subject: [boost] [parameter] type requirement compiler error
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-10-24 13:00:55


Hello all,

The following parameter type requirement:

    (required (graph, *) )
    (optional (root_vertex,
                (typename
boost::graph_traits<graph_type>::vertex_descriptor),
                *boost::vertices(graph).first) )

Generates a GCC error:

dfs.05.cpp:40: error: ‘graph_type’ was not declared in this scope

Detailed code and error below.

In fact, if I look at the code after pp, I can see that graph_type is define
only after the type requirement is checked... why? What am I doing wrong?

Thanks a lot!
--Lorenzo

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/range/irange.hpp>
#include <boost/pending/indirect_cmp.hpp>
#include <boost/parameter.hpp>
#include <iostream>

namespace graphs {

BOOST_PARAMETER_NAME(graph)
BOOST_PARAMETER_NAME(visitor)
BOOST_PARAMETER_NAME(root_vertex)
BOOST_PARAMETER_NAME(index_map)
BOOST_PARAMETER_NAME(color_map)

template< typename Size, typename IndexMap >
boost::iterator_property_map<boost::default_color_type*, IndexMap,
        boost::default_color_type, boost::default_color_type&amp;>
default_color_map ( Size const& num_vertices, IndexMap const& index_map )
{
    std::vector<boost::default_color_type> colors(num_vertices);
    return &colors[0];
}

BOOST_PARAMETER_FUNCTION(
    (void),
    depth_first_search,
    tag,
    (required (graph, *))
    (optional
        (visitor, *, boost::dfs_visitor<>())
        (root_vertex,
                (typename
boost::graph_traits<graph_type>::vertex_descriptor),
                *boost::vertices(graph).first)
        (index_map, *, boost::get(boost::vertex_index, graph))
        (in_out(color_map), *,
                default_color_map(boost::num_vertices(graph), index_map))
    )
) {
    std::cout << "here\n";
    boost::depth_first_search(graph, boost::visitor(visitor).
            color_map(color_map).root_vertex(root_vertex).
            vertex_index_map(index_map));
}

} // namespace graphs

template< typename TimeMap >
class dfs_time_visitor : public boost::default_dfs_visitor
{
    typedef typename boost::property_traits< TimeMap >::value_type T;
public:
    dfs_time_visitor(TimeMap dmap, TimeMap fmap, T& t)
        : dmap_(dmap), fmap_(fmap), time_(t)
    {}

    template< typename V, typename G >
    void discover_vertex ( V u, G const& g ) const { put(dmap_, u, time_++);
}

    template< typename V, typename G >
    void finish_vertex ( V u, G const& g ) const { put(fmap_, u, time_++); }

    TimeMap dmap_;
    TimeMap fmap_;
    T& time_;
};

using namespace boost;

int main ( )
{
    typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::directedS> G;
    typedef boost::graph_traits<G>::vertices_size_type size_type;

    enum {u, v, w, x, y, z, N};
    char names[] = {'u', 'v', 'w', 'x', 'y', 'z'};
    typedef std::pair<int, int> E;
    E edges[] = {E(u, v), E(u, x), E(x, v), E(y, x), E(v, y), E(w, y), E(w,
z),
            E(z, z)};
    G g(edges, edges + sizeof(edges) / sizeof(E), N);

    std::vector<size_type> dtime(boost::num_vertices(g));
    std::vector<size_type> ftime(boost::num_vertices(g));
    size_type t = 0;
    dfs_time_visitor<size_type*> vis(&dtime[0], &ftime[0], t);

    graphs::depth_first_search(g, vis);

    std::vector<size_type> dorder(N);
    boost::integer_range<size_type> r(0, N);
    std::copy(r.begin(), r.end(), dorder.begin());
    std::sort(dorder.begin(), dorder.end(),
            boost::indirect_cmp<size_type*, std::less&lt;size_type>
>(&dtime[0]));
    std::cout << "order of discovery: ";
    for(int i = 0; i < N; ++i) std::cout << names[dorder[i]] << " ";
    std::cout << std::endl;

    std::vector<size_type> forder(N);
    std::copy(r.begin(), r.end(), forder.begin());
    std::sort(forder.begin(), forder.end(),
            boost::indirect_cmp<size_type*, std::less&lt;size_type>
>(&ftime[0]));
    std::cout << "order of finish: ";
    for(int i = 0; i < N; ++i) std::cout << names[forder[i]] << " ";
    std::cout << std::endl;

    return 0;
}

$ g++ -Wall -I../../../../../boost-trunk.cygwin dfs.05.cpp
dfs.05.cpp:40: error: ‘graph_type’ was not declared in this scope
dfs.05.cpp:40: error: template argument 1 is invalid
dfs.05.cpp:40: error: expected `::' before ‘,’ token
dfs.05.cpp:40: error: expected identifier before ‘,’ token
dfs.05.cpp:40: error: template argument 3 is invalid
dfs.05.cpp:40: error: expected `::' before ‘{’ token
dfs.05.cpp:40: error: expected class-name before ‘{’ token
../../../../../boost-trunk.cygwin/boost/parameter/preprocessor.hpp: In
instantiation of
‘boost::parameter::aux::argument_pack<graphs::boost_param_params_40depth_first_search&lt;int>,
const boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::no_property, boost::no_property, boost::no_property, boost::listS>,
const dfs_time_visitor<main::size_type*>, boost::parameter::void_,
boost::parameter::void_, boost::parameter::void_>’:
dfs.05.cpp:88: instantiated from here
../../../../../boost-trunk.cygwin/boost/parameter/preprocessor.hpp:157:
error: no type named ‘parameter_spec0’ in ‘struct
graphs::boost_param_params_40depth_first_search<int>’
../../../../../boost-trunk.cygwin/boost/parameter/preprocessor.hpp:158:
error: no type named ‘parameter_spec0’ in ‘struct
graphs::boost_param_params_40depth_first_search<int>’
../../../../../boost-trunk.cygwin/boost/parameter/preprocessor.hpp: In
instantiation of
‘boost::parameter::aux::argument_pack<graphs::boost_param_params_40depth_first_search&lt;int>,
const boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::no_property, boost::no_property, boost::no_property, boost::listS>,
boost::parameter::void_, boost::parameter::void_, boost::parameter::void_,
boost::parameter::void_>’:
dfs.05.cpp:88: instantiated from here
../../../../../boost-trunk.cygwin/boost/parameter/preprocessor.hpp:157:
error: no type named ‘parameter_spec0’ in ‘struct
graphs::boost_param_params_40depth_first_search<int>’
../../../../../boost-trunk.cygwin/boost/parameter/preprocessor.hpp:158:
error: no type named ‘parameter_spec0’ in ‘struct
graphs::boost_param_params_40depth_first_search<int>’
dfs.05.cpp: In function ‘int main()’:
dfs.05.cpp:88: error: no matching function for call to
‘depth_first_search(main()::G&, dfs_time_visitor<size_type*>&)’

--
View this message in context: http://boost.2283326.n4.nabble.com/boost-parameter-type-requirement-compiler-error-tp3933830p3933830.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk