1 /*============================================================================= 2 Copyright (c) 2001-2011 Joel de Guzman 3 Copyright (c) 2006 Dan Marsden 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 ==============================================================================*/ 8 #if !defined(BOOST_FUSION_SWAP_20070501_1956) 9 #define BOOST_FUSION_SWAP_20070501_1956 10 11 #include <boost/fusion/support/config.hpp> 12 #include <algorithm> 13 14 #include <boost/fusion/support/is_sequence.hpp> 15 #include <boost/fusion/view/zip_view.hpp> 16 #include <boost/fusion/algorithm/iteration/for_each.hpp> 17 #include <boost/fusion/sequence/intrinsic/front.hpp> 18 #include <boost/fusion/sequence/intrinsic/back.hpp> 19 #include <boost/core/enable_if.hpp> 20 #include <boost/mpl/and.hpp> 21 22 namespace boost { namespace fusion { 23 24 namespace result_of 25 { 26 template<typename Seq1, typename Seq2> 27 struct swap 28 : enable_if<mpl::and_< 29 traits::is_sequence<Seq1>, 30 traits::is_sequence<Seq2> 31 > > {}; 32 } 33 34 namespace detail 35 { 36 struct swap 37 { 38 template<typename Elem> 39 struct result 40 { 41 typedef void type; 42 }; 43 44 template<typename Elem> 45 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED operator ()boost::fusion::detail::swap46 void operator()(Elem const& e) const 47 { 48 using std::swap; 49 swap(front(e), back(e)); 50 } 51 }; 52 } 53 54 template<typename Seq1, typename Seq2> 55 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED 56 inline typename result_of::swap<Seq1, Seq2>::type swap(Seq1 & lhs,Seq2 & rhs)57 swap(Seq1& lhs, Seq2& rhs) 58 { 59 typedef vector<Seq1&, Seq2&> references; 60 for_each(zip_view<references>(references(lhs, rhs)), detail::swap()); 61 } 62 }} 63 64 #endif 65