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