annotate DEPENDENCIES/generic/include/boost/utility/swap.hpp @ 16:2665513ce2d3

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