Используете прямоугольник_топологии‹›::point_type с динамическими картами свойств и связанными свойствами BGL?

Я пытаюсь использовать write_graphviz_dp() для сериализации графа Boost, содержащего экземпляры rectangle_topology<>::point_type в связанных свойствах, в файл 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>
]

Как я могу это исправить? Есть ли лучший/другой способ использовать Point с dynamic_properties?


person genpfault    schedule 25.07.2013    source источник
comment
Помещение обоих операторов потоковой передачи Point внутри namespace boost заставляет ваш код компилироваться с помощью g++ 4.8.1.   -  person llonesmiz    schedule 25.07.2013
comment
@cv_and_he: Ура! Работает и в VS2012. Шлепните это в ответ, и я приму это.   -  person genpfault    schedule 25.07.2013
comment
Это был бы хромой ответ, я уверен, что кто-то (возможно, вы сами) сможет дать лучший ответ.   -  person llonesmiz    schedule 25.07.2013
comment
stackoverflow.com/a/3623643/2417774   -  person llonesmiz    schedule 25.07.2013