GCC swap workaround added

[SVN r17065]
This commit is contained in:
Fernando Cacciola
2003-01-28 15:18:50 +00:00
parent 4456cc1660
commit 8068c1db25

View File

@ -240,13 +240,25 @@ inline
bool operator != ( optional<T> const& x, optional<T> const& y ) bool operator != ( optional<T> const& x, optional<T> const& y )
{ return !( x == y ) ; } { return !( x == y ) ; }
//
// The following swap implementation follows the GCC workaround as found in
// "boost/detail/compressed_pair.hpp"
//
namespace optional_detail {
#ifdef __GNUC__
// workaround for GCC (JM):
using std::swap;
#endif
// optional's swap: // optional's swap:
// If both are initialized, calls swap(T&, T&), with whatever exception guarantess are given there. // If both are initialized, calls swap(T&, T&), with whatever exception guarantess are given there.
// If only one is initialized, calls I.reset() and U.reset(*I), with the Basic Guarantee // If only one is initialized, calls I.reset() and U.reset(*I), with the Basic Guarantee
// If both are uninitialized, do nothing (no-throw) // If both are uninitialized, do nothing (no-throw)
template<class T> template<class T>
inline inline
void swap ( optional<T>& x, optional<T>& y ) void optional_swap ( optional<T>& x, optional<T>& y )
{ {
if ( !x && !!y ) if ( !x && !!y )
{ {
@ -260,11 +272,21 @@ void swap ( optional<T>& x, optional<T>& y )
} }
else if ( !!x && !!y ) else if ( !!x && !!y )
{ {
#ifndef __GNUC__
using std::swap ; using std::swap ;
#endif
swap(*x,*y); swap(*x,*y);
} }
} }
} // namespace optional_detail
template<class T> inline void swap ( optional<T>& x, optional<T>& y )
{
optional_detail::optional_swap(x,y);
}
} // namespace boost } // namespace boost
#endif #endif