|
Boost Users : |
From: Ewan Campbell (ewancampbell_at_[hidden])
Date: 2004-10-20 06:57:15
>> I appear to have made a small error, the warning occurs 'whenever'
>> resize is called.
>>
>> So the problem now is:
>>
>> Every time the resize function of multi_array is called, a warning is
>> generated in the use of MSVC++ 6.0's implementation of std::swap.
>>
>> The problem is solved by commenting out the line
>> swap(this->allocator_,new_array.allocator_);
>> in multi_array.hpp
>>
> In general, I'd say this is a dangerous thing to do, particularly
> because I don't know how std::swap is implemented in your compiler.
> It seems like the compiler is complaining about an unused variable in
> the implementation, which does not mean that the allocators are not
> being swapped.
>
>> This hasn't incurred an execution problem under debug or release.
>> Could someone explain this? What is the purpose of this line, and why
>> wasn't it swapping the allocators?
>>
>
> The resize operation preserves as much of the contents of the
> original array as possible. To do so, it must allocate a new portion
> of memory and copy the salvageable elements to it. The algorithm
> essentially builds a new array of the right size and swaps the guts of
> the original array out.
The MSVC++ 6.0 compiler implements swap like so:
template<class _Ty> inline
void swap(_Ty& _X, _Ty& _Y)
{_Ty _Tmp = _X;
_X = _Y, _Y = _Tmp; }
The unreferenced local variable warning is referring to _Tmp. Since _Tmp
is required to swap the variables, does this not indicate that this
particular use of the swap function is redundant?
Thanks again,
Ewan
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