将rectangle_topology<> :: point_type与动态属性映射和BGL捆绑属性一起使用?

时间:2013-07-25 15:15:30

标签: c++ boost visual-studio-2012 boost-graph

我正在尝试使用write_graphviz_dp()将包含捆绑属性中rectangle_topology<>::point_type实例的Boost图序列化为DOT文件。

这是一个精简的例子:

#include <iostream>

// Boost 1.49
#include <boost/graph/topology.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/dynamic_property_map.hpp>

using namespace std;
using namespace boost;

typedef rectangle_topology<> Topology;
typedef Topology::point_type Point;
ostream& operator<<( ostream& out, const Point& pt )
{
    return out;
}
istream& operator>>( istream& in, Point& pt )
{
    return in;
}

struct Foo
{
    float value;
};
ostream& operator<<( ostream& out, const Foo& foo )
{
    return out;
}
istream& operator>>( istream& in, Foo& foo )
{
    return in;
}

struct VertProps
{
    Foo foo;
    Point pos;
};

typedef adjacency_list< vecS, vecS, undirectedS, VertProps > Graph;

int main( int argc, char** argv )
{
    Graph g;
    dynamic_properties dp;

    // #1: works
    dp.property( "foo", get( &VertProps::foo, g ) );

    // #2: dies horrible death in the compiler
    //     despite seemingly valid operator<< overload
    dp.property( "pos", get( &VertProps::pos, g ) );

    return 0;
}

为自定义类型(“operator<<”)提供operator>>Foo重载,编译时没有错误(行#1)。

Point 执行相同的操作无法正常工作(第#2行):

c:\boost\include\boost\property_map\dynamic_property_map.hpp(198): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Point' (or there is no acceptable conversion)
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(695): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(742): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(780): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(827): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(953): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(960): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(967): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(974): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(984): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,T>(std::basic_ostream<_Elem,_Traits> &&,const _Ty &)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>,
    T=Point,
    _Ty=Point
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(1101): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' [found using argument-dependent lookup]
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(201): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(207): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(214): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(221): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(241): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(275): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(295): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(320): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(340): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(360): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(381): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(401): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(422): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(442): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(462): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(482): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\program files (x86)\microsoft visual studio 11.0\vc\include\ostream(502): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
while trying to match the argument list '(std::ostringstream, Point)'
c:\boost\include\boost\property_map\dynamic_property_map.hpp(189) : while compiling class template member function 'std::string boost::detail::dynamic_property_map_adaptor<PropertyMap>::get_string(const boost::any &)'
with
[
    PropertyMap=boost::bundle_property_map<boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS,VertProps>,unsigned int,VertProps,Point>
]
c:\boost\include\boost\property_map\dynamic_property_map.hpp(250) : see reference to class template instantiation 'boost::detail::dynamic_property_map_adaptor<PropertyMap>' being compiled
with
[
    PropertyMap=boost::bundle_property_map<boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS,VertProps>,unsigned int,VertProps,Point>
]
c:\test\main.cpp(53) : see reference to function template instantiation 'boost::dynamic_properties &boost::dynamic_properties::property<boost::bundle_property_map<Graph,Descriptor,Bundle,T>>(const std::string &,PropertyMap)' being compiled
with
[
    Graph=boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS,VertProps>,
    Descriptor=unsigned int,
    Bundle=VertProps,
    T=Point,
    PropertyMap=boost::bundle_property_map<boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS,VertProps>,unsigned int,VertProps,Point>
]

我该如何解决这个问题?是否有更好/不同的方式将Pointdynamic_properties一起使用?

0 个答案:

没有答案