Chris@16: // Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // For more information, see http://www.boost.org Chris@16: Chris@16: Chris@16: #ifndef BOOST_UTILITY_SWAP_HPP Chris@16: #define BOOST_UTILITY_SWAP_HPP Chris@16: Chris@16: // Note: the implementation of this utility contains various workarounds: Chris@16: // - swap_impl is put outside the boost namespace, to avoid infinite Chris@16: // recursion (causing stack overflow) when swapping objects of a primitive Chris@16: // type. Chris@16: // - swap_impl has a using-directive, rather than a using-declaration, Chris@16: // because some compilers (including MSVC 7.1, Borland 5.9.3, and Chris@16: // Intel 8.1) don't do argument-dependent lookup when it has a Chris@16: // using-declaration instead. Chris@16: // - boost::swap has two template arguments, instead of one, to Chris@16: // avoid ambiguity when swapping objects of a Boost type that does Chris@16: // not have its own boost::swap overload. Chris@16: Chris@16: #include //for std::swap Chris@16: #include //for std::size_t Chris@16: Chris@16: namespace boost_swap_impl Chris@16: { Chris@16: template Chris@16: void swap_impl(T& left, T& right) Chris@16: { Chris@16: using namespace std;//use std::swap if argument dependent lookup fails Chris@16: swap(left,right); Chris@16: } Chris@16: Chris@16: template Chris@16: void swap_impl(T (& left)[N], T (& right)[N]) Chris@16: { Chris@16: for (std::size_t i = 0; i < N; ++i) Chris@16: { Chris@16: ::boost_swap_impl::swap_impl(left[i], right[i]); Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: template Chris@16: void swap(T1& left, T2& right) Chris@16: { Chris@16: ::boost_swap_impl::swap_impl(left, right); Chris@16: } Chris@16: } Chris@16: Chris@16: #endif