Chris@102
|
1 // Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker
|
Chris@102
|
2 //
|
Chris@102
|
3 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@102
|
4 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
5 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
6 // For more information, see http://www.boost.org
|
Chris@102
|
7
|
Chris@102
|
8
|
Chris@102
|
9 #ifndef BOOST_CORE_SWAP_HPP
|
Chris@102
|
10 #define BOOST_CORE_SWAP_HPP
|
Chris@102
|
11
|
Chris@102
|
12 // Note: the implementation of this utility contains various workarounds:
|
Chris@102
|
13 // - swap_impl is put outside the boost namespace, to avoid infinite
|
Chris@102
|
14 // recursion (causing stack overflow) when swapping objects of a primitive
|
Chris@102
|
15 // type.
|
Chris@102
|
16 // - swap_impl has a using-directive, rather than a using-declaration,
|
Chris@102
|
17 // because some compilers (including MSVC 7.1, Borland 5.9.3, and
|
Chris@102
|
18 // Intel 8.1) don't do argument-dependent lookup when it has a
|
Chris@102
|
19 // using-declaration instead.
|
Chris@102
|
20 // - boost::swap has two template arguments, instead of one, to
|
Chris@102
|
21 // avoid ambiguity when swapping objects of a Boost type that does
|
Chris@102
|
22 // not have its own boost::swap overload.
|
Chris@102
|
23
|
Chris@102
|
24 #include <utility> //for std::swap (C++11)
|
Chris@102
|
25 #include <algorithm> //for std::swap (C++98)
|
Chris@102
|
26 #include <cstddef> //for std::size_t
|
Chris@102
|
27 #include <boost/config.hpp>
|
Chris@102
|
28
|
Chris@102
|
29 namespace boost_swap_impl
|
Chris@102
|
30 {
|
Chris@102
|
31 template<class T>
|
Chris@102
|
32 BOOST_GPU_ENABLED
|
Chris@102
|
33 void swap_impl(T& left, T& right)
|
Chris@102
|
34 {
|
Chris@102
|
35 using namespace std;//use std::swap if argument dependent lookup fails
|
Chris@102
|
36 swap(left,right);
|
Chris@102
|
37 }
|
Chris@102
|
38
|
Chris@102
|
39 template<class T, std::size_t N>
|
Chris@102
|
40 BOOST_GPU_ENABLED
|
Chris@102
|
41 void swap_impl(T (& left)[N], T (& right)[N])
|
Chris@102
|
42 {
|
Chris@102
|
43 for (std::size_t i = 0; i < N; ++i)
|
Chris@102
|
44 {
|
Chris@102
|
45 ::boost_swap_impl::swap_impl(left[i], right[i]);
|
Chris@102
|
46 }
|
Chris@102
|
47 }
|
Chris@102
|
48 }
|
Chris@102
|
49
|
Chris@102
|
50 namespace boost
|
Chris@102
|
51 {
|
Chris@102
|
52 template<class T1, class T2>
|
Chris@102
|
53 BOOST_GPU_ENABLED
|
Chris@102
|
54 void swap(T1& left, T2& right)
|
Chris@102
|
55 {
|
Chris@102
|
56 ::boost_swap_impl::swap_impl(left, right);
|
Chris@102
|
57 }
|
Chris@102
|
58 }
|
Chris@102
|
59
|
Chris@102
|
60 #endif
|