|
Boost Users : |
Subject: Re: [Boost-users] [boost::variant] problem with swap
From: Ondrej Kuncar (kxenator_at_[hidden])
Date: 2009-12-20 11:44:47
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net