diff --git a/include/boost/optional.hpp b/include/boost/optional.hpp index e28fb79..ca4a976 100644 --- a/include/boost/optional.hpp +++ b/include/boost/optional.hpp @@ -240,13 +240,25 @@ inline bool operator != ( optional const& x, optional const& 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: // 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 both are uninitialized, do nothing (no-throw) template inline -void swap ( optional& x, optional& y ) +void optional_swap ( optional& x, optional& y ) { if ( !x && !!y ) { @@ -260,11 +272,21 @@ void swap ( optional& x, optional& y ) } else if ( !!x && !!y ) { +#ifndef __GNUC__ using std::swap ; +#endif swap(*x,*y); } } +} // namespace optional_detail + +template inline void swap ( optional& x, optional& y ) +{ + optional_detail::optional_swap(x,y); +} + + } // namespace boost #endif