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