mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-16 05:42:20 +02:00
swap implementation
[SVN r37552]
This commit is contained in:
59
include/boost/fusion/sequence/intrinsic/swap.hpp
Normal file
59
include/boost/fusion/sequence/intrinsic/swap.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_SWAP_20070501_1956)
|
||||
#define BOOST_FUSION_SWAP_20070501_1956
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/fusion/support/is_sequence.hpp>
|
||||
#include <boost/fusion/sequence/view/zip_view.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/front.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/back.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
namespace result_of
|
||||
{
|
||||
template<typename Seq1, typename Seq2>
|
||||
struct swap
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct swap
|
||||
{
|
||||
template<typename Elem>
|
||||
struct result
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template<typename Elem>
|
||||
void operator()(Elem& e) const
|
||||
{
|
||||
using std::swap;
|
||||
swap(front(e), back(e));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename Seq1, typename Seq2>
|
||||
typename enable_if<mpl::and_<traits::is_sequence<Seq1>, traits::is_sequence<Seq2> >, void>::type
|
||||
swap(Seq1& lhs, Seq2& rhs)
|
||||
{
|
||||
typedef vector<Seq1&, Seq2&> references;
|
||||
for_each(zip_view<references>(references(lhs, rhs)), detail::swap());
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user