Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-08-05 09:19:33


Alisdair Meredith <alisdair.meredith_at_[hidden]> writes:

> There is a problem with the Borland BCB6 compiler specializing std::swap
> for user defined types when using the STLport standard library. This
> may apply to other compilers using the library as well, but only have
> experience with Borland.
>
> An example is the clearest demonstration:
>
> // ----- Begin example
> #include <boost/shared_ptr.hpp>
>
> class Swappable
> {
> public:
> Swappable() {}
>
> void Swap( Swappable & ) { }
> };
>
> namespace std
> {
> template<>
> void swap( Swappable &lhs, Swappable &rhs )
> {
> lhs.Swap( rhs );
> }
>
> }
>
> int main(int argc, char* argv[])
> {
> Swappable a, b;
> std::swap( a, b );
>
> boost::shared_ptr<Swappable> pA( new Swappable() );
> boost::shared_ptr<Swappable> pB( new Swappable() );
> # if BOOST_WORKAROUND( __BORLANDC__, >= 0x0560 )
> _STL::swap( pA, pB );
> # else
> std::swap( pA, pB );
> # endif
> return 0;
> }
> // ----- End example
>
> If the workaround is disabled, the compiler cannot find the
> specialization in namespace std as the swap algorithm is implemented in
> namespace _STL and introduced by a namespace alias.
>
> What does this mean for Boost?
> i/ There are no test cases for this in the test suite, or BCB would be
> failing more tests!
> ii/ Anywhere we use std::swap, we need a borland hack as above (although
> better tuned to STLport version as well)

Err, I don't get it. It seems to me that you only need the hack if
you're going to *specialize* swap. *Using* std::swap should work just
fine.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk