[boost::variant] problem with swap
Hello! I have problems to compile this code with Visual Studio 9.0 SP1 and Boost 1.41: ------------------------------------------------------------------- #include <boost/variant.hpp> #include <deque> typedef boost::variant<std::deque<int>::iterator> SemanticValue; int main() { SemanticValue v1; SemanticValue v2; v1.swap(v2); } ------------------------------------------------------------------- I got this error: c:\program files\boost\boost_1_41_0\boost\variant\detail\move.hpp(155) : error C2668: 'std::swap' : ambiguous call to overloaded function c:\program files\boost\boost_1_41_0\boost\variant\detail\move.hpp(141): could be 'void boost::detail::variant::detail::move_swap::swap<T>(T &,T &)' with [ T=T0 ] c:\program files\microsoft visual studio 9.0\vc\include\utility(16): or 'void std::swap<T>(_Ty &,_Ty &)' [found using argument-dependent lookup] with [ T=T0, _Ty=T0 ] while trying to match the argument list '(T0, T0)' c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(698) : see reference to function template instantiation 'void boost::detail::variant::move_swap<T>(T &,T &)' being compiled with [ T=T0 ] c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(825) : see reference to function template instantiation 'void boost::detail::variant::swap_with<Variant>::operator ()<T>(T &) const' being compiled with [ Variant=boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>, T=T0 ] c:\program files\boost\boost_1_41_0\boost\variant\detail\visitation_impl.hpp(141) : see reference to function template instantiation 'void boost::detail::variant::invoke_visitor<Visitor>::internal_visit<T>(T &,int)' being compiled with [ Visitor=boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>>, T=T0 ] c:\program files\boost\boost_1_41_0\boost\variant\detail\visitation_impl.hpp(169) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl_invoke_impl<Visitor,VoidPtrCV,T>(int,Visitor &,VoidPtrCV,T *,boost::mpl::false_)' being compiled with [ Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>>>, VoidPtrCV=void *, T=T0 ] c:\program files\boost\boost_1_41_0\boost\variant\detail\visitation_impl.hpp(252) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl_invoke<Visitor,VoidPtrCV,T0,NoBackupFlag>(int,Visitor &,VoidPtrCV,T *,NoBackupFlag,int)' being compiled with [ Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>>>, VoidPtrCV=void *, NoBackupFlag=boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>::has_fallback_type_, T=T0 ] c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(1769) : see reference to function template instantiation 'void boost::detail::variant::visitation_impl<first_which,first_step,Visitor,VoidPtrCV,boost::variant<T0_>::has_fallback_type_>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' being compiled with [ Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>>>, VoidPtrCV=void *, T0_=std::_Deque_iterator<int,std::allocator<int>,true>, NoBackupFlag=boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>::has_fallback_type_, Which=first_which, step0=first_step ] c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(1780) : see reference to function template instantiation 'void boost::variant<T0_>::internal_apply_visitor_impl<Visitor,void*>(int,int,Visitor &,VoidPtrCV)' being compiled with [ T0_=std::_Deque_iterator<int,std::allocator<int>,true>, Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>>>, VoidPtrCV=void * ] c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(1803) : see reference to function template instantiation 'void boost::variant<T0_>::internal_apply_visitor<boost::detail::variant::invoke_visitor<Visitor>>(boost::detail::variant::invoke_visitor<Visitor> &)' being compiled with [ T0_=std::_Deque_iterator<int,std::allocator<int>,true>, Visitor=boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>> ] c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(1637) : see reference to function template instantiation 'void boost::variant<T0_>::apply_visitor<boost::detail::variant::swap_with<Variant>>(Visitor &)' being compiled with [ T0_=std::_Deque_iterator<int,std::allocator<int>,true>, Variant=boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>, Visitor=boost::detail::variant::swap_with<boost::variant<std::_Deque_iterator<int,std::allocator<int>,true>>> ] c:\program files\boost\boost_1_41_0\boost\variant\variant.hpp(1631) : while compiling class template member function 'void boost::variant<T0_>::swap(boost::variant<T0_> &)' with [ T0_=std::_Deque_iterator<int,std::allocator<int>,true> ] d:\dokumenty\visual studio 2008\projects\pokus4\pokus4\pokus4.cpp(20) : see reference to class template instantiation 'boost::variant<T0_>' being compiled with [ T0_=std::_Deque_iterator<int,std::allocator<int>,true> ] Do you have any ideas? Thanks. OK
AMDG Ondrej Kuncar wrote:
I have problems to compile this code with Visual Studio 9.0 SP1 and Boost 1.41:
-------------------------------------------------------------------
#include <boost/variant.hpp> #include <deque>
typedef boost::variant<std::deque<int>::iterator> SemanticValue;
int main() { SemanticValue v1; SemanticValue v2; v1.swap(v2); }
-------------------------------------------------------------------
I got this error:
c:\program files\boost\boost_1_41_0\boost\variant\detail\move.hpp(155) : error C2668: 'std::swap' : ambiguous call to overloaded function c:\program files\boost\boost_1_41_0\boost\variant\detail\move.hpp(141): could be 'void boost::detail::variant::detail::move_swap::swap<T>(T &,T &)' with [ T=T0 ] c:\program files\microsoft visual studio 9.0\vc\include\utility(16): or 'void std::swap<T>(_Ty &,_Ty &)' [found using argument-dependent lookup] with [ T=T0, _Ty=T0 ] while trying to match the argument list '(T0, T0)' <snip>
Do you have any ideas?
This is a known bug. I believe that there's an open trac ticket for it. I don't think anyone has found a good solution yet. In Christ, Steven Watanabe
On 20.12.2009 16:53, Steven Watanabe wrote:
AMDG
Ondrej Kuncar wrote:
I have problems to compile this code with Visual Studio 9.0 SP1 and Boost 1.41:
-------------------------------------------------------------------
#include <boost/variant.hpp> #include <deque>
typedef boost::variant<std::deque<int>::iterator> SemanticValue;
int main() { SemanticValue v1; SemanticValue v2; v1.swap(v2); }
-------------------------------------------------------------------
I got this error:
c:\program files\boost\boost_1_41_0\boost\variant\detail\move.hpp(155) : error C2668: 'std::swap' : ambiguous call to overloaded function c:\program files\boost\boost_1_41_0\boost\variant\detail\move.hpp(141): could be 'void boost::detail::variant::detail::move_swap::swap<T>(T &,T &)' with [ T=T0 ] c:\program files\microsoft visual studio 9.0\vc\include\utility(16): or 'void std::swap<T>(_Ty &,_Ty &)' [found using argument-dependent lookup] with [ T=T0, _Ty=T0 ] while trying to match the argument list '(T0, T0)' <snip>
Do you have any ideas?
This is a known bug. I believe that there's an open trac ticket for it. I don't think anyone has found a good solution yet.
In Christ, Steven Watanabe
You are right, it's https://svn.boost.org/trac/boost/ticket/2839 It seems for me that only reasonable workaround is the following hack: ------------------------------------------------------------------ #include <boost/variant.hpp> #include <deque> typedef boost::variant<std::deque<int>::iterator> SemanticValue; namespace std { inline void swap(std::deque<int>::iterator &s1, std::deque<int>::iterator &s2) { std::swap<std::deque<int>::iterator>(s1,s2); } } int main() { SemanticValue v1; SemanticValue v2; v1.swap(v2); } ------------------------------------------------------------------ OK
participants (2)
-
Ondrej Kuncar
-
Steven Watanabe