I am trying to store vectors in the vertices of the boost graph. I am running into problems reading from file using the boost::read_graphviz function. Compiling breaks due to the line that relates the vertex content to the dynamic properties.
Here is a simplified version (let's call it test.cpp):
#include <iostream>
#include <vector>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <fstream>
struct Vertex
{
std::vector<int> p;
};
struct Edge
{
double w;
};
// this should be necessary, but is not 'seen' by compiler
std::ostream &
operator << ( std::ostream &OUT, const std::vector<int> &P)
{
OUT << P.size() << " ";
for( int i = 0; i < P.size(); ++i)
OUT << P[i] << " ";
return OUT;
}
// also doesn't help (and also should not be necessary as ostringstream is derived from ostream (or?)
std::ostringstream &
operator << ( std::ostringstream &OUT, const std::vector<int> &P)
{
OUT << P.size() << " ";
for( int i = 0; i < P.size(); ++i)
OUT << P[i] << " ";
return OUT;
}
int main()
{
typedef boost::adjacency_list<boost::setS, boost::setS, boost::bidirectionalS, Vertex, Edge>
Graph;
Graph
graph;
std::ifstream
in;
boost::dynamic_properties
dp;
dp.property("vector", get( &Vertex::p, graph)); // the critical line
dp.property("value", get( &Edge::w, graph));
boost::read_graphviz( in, graph, dp);
}
I compile this using
g++ test.cpp -lboost_graph
And get the following error message (first block only):
In file included from /usr/include/boost/graph/graphviz.hpp:25:0,
from boost_graph_test.cpp:4:
/usr/include/boost/property_map/dynamic_property_map.hpp: In instantiation of ‘std::string boost::detail::dynamic_property_map_adaptor<PropertyMap>::get_string(const boost
::any&) [with PropertyMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::setS, boost::bidirectionalS, Vertex, Edge>, std::vector<int>, std
::vector<int>&, std::vector<int> Vertex::*>; std::string = std::basic_string<char>]’:
boost_graph_test.cpp:58:1: required from here
/usr/include/boost/property_map/dynamic_property_map.hpp:180:9: error: no match for ‘operator<<’ (operand types are ‘std::ostringstream {aka std::basic_ostringstream<char>}’ and ‘std::vector<int>’)
out << get_wrapper_xxx(property_map_, any_cast<typename boost::property_traits<PropertyMap>::key_type>(key));
The issue is the line marked as critical. When commented out, it compiles. What am I doing wrong?