Problems using predicate checking with the Boost Parameter library

447 views Asked by At

I am fairly new to using Boost (the Boost Graph Library actually), and am trying to write my first graph algorithm. Since my algorithm will require several optional and defaultable parameters to be passed in to it, I thought I would try to use the Boost::Parameter library. As I understand things, this is an improvement over the older BGL named parameter system which is widely used in the BGL.

I have been working from the tutorial here. The first simple sample from the tutorial works fine, but I get lots of incomprehensible compiler errors when I try to use predicate requirements to check that my parameters match the algorithm pre-conditions.

The following test code is my stripped-down version of the predicate checking example from the tutorial.

#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/parameter/name.hpp>
#include <boost/parameter/preprocessor.hpp>

namespace graphs
{
  BOOST_PARAMETER_NAME(graph)

  BOOST_PARAMETER_FUNCTION(
    (void), my_algorithm, tag,

    (required
      (graph,
        *(boost::mpl::and_<
               boost::is_convertible<
                   boost::graph_traits<_>::traversal_category
                 , boost::incidence_graph_tag
               >
             , boost::is_convertible<
                   boost::graph_traits<_>::traversal_category
                 , boost::vertex_list_graph_tag
              >
           >)
      )
    )
  )
  {
    // ... body of function goes here...
    std::cout << "graph=" << graph << std::endl;
  }
}

int main(int argc, char* argv[])
{
  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> Graph;

  Graph g(3); // Create a graph with 3 vertices.

  boost::add_edge(0, 1, g);
  boost::add_edge(1, 2, g);

  graphs::my_algorithm(graphs::_graph = g);

  return 0;
}

These are the error messages from the compiler:

error C2065: '_' : undeclared identifier error C2923: 'boost::is_convertible' : 'boost::graph_traits::traversal_category' is not a valid template type argument for parameter 'From' error C2065: '_' : undeclared identifier error C2923: 'boost::is_convertible' : 'boost::graph_traits::traversal_category' is not a valid template type argument for parameter 'From' error C3203: 'is_convertible' : unspecialized class template can't be used as a template argument for template parameter 'T1', expected a real type error C2955: 'boost::is_convertible' : use of class template requires template argument list error C3203: 'is_convertible' : unspecialized class template can't be used as a template argument for template parameter 'T2', expected a real type error C2955: 'boost::is_convertible' : use of class template requires template argument list error C2065: '_' : undeclared identifier error C2955: 'boost::graph_traits' : use of class template requires template argument list error C2065: '_' : undeclared identifier error C2955: 'boost::graph_traits' : use of class template requires template argument list error C1903: unable to recover from previous error(s); stopping compilation

I think that the problem is something to do with the parenthesised underscores in lines like: boost::graph_traits<_>::traversal_category

However I really don't know what is going on, and would very much appreciate any advice on how to correct things. Some pointers to more code samples and user documentation for this would also be very helpful. The parameter library looks very powerful, and I am prepared to spend some time learning how to use it effectively.

I am using Boost 1.47 with Microsoft Visual Studio 2010.

0

There are 0 answers