/*
* Author:
* Stjepan Rajko
* Arts, Media and Engineering Program
* Arizona State University
*
* Copyright 2008 Arizona Board of Regents.
*
* This file is part of the Arts, Media and Engineering Library Assortment (AMELiA).
*
* AMELiA is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* AMELiA is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AMELiA.
* If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
namespace ame { namespace utility {
namespace detail
{
// accesses the specified index of a Sequence - used to transform a Range
template
struct access_index
{
typedef access_index next_access_index;
typedef boost::range_detail::transform_range result_type;
result_type operator()(const typename RangeRange::value_type &element) const
{
return element | boost::adaptors::transformed(
next_access_index());
}
};
template
struct access_index
{
typedef typename boost::fusion::result_of::at_c::type result_type;
result_type operator()(const typename Range::value_type &element) const
{
return boost::fusion::at_c(element);
}
};
template
struct for_each_element_and_slice
{
typedef void result_type;
for_each_element_and_slice(const Range &range, const F &f)
: range(range), f(f) {}
// Pair is a
template
result_type operator()(const Pair &pair) const
{
namespace fusion=boost::fusion;
namespace mpl = boost::mpl;
f(fusion::at_c<1>(pair),
range | boost::adaptors::transformed(
access_index::type::value, Depth>()));
}
const Range ⦥
F f;
};
}
template
void for_each_element_and_slice(Sequence &sequence, const Range &range, const F &f)
{
namespace fusion=boost::fusion;
namespace mpl=boost::mpl;
typedef mpl::range_c::value> indices_type;
indices_type indices;
typedef fusion::vector zipped_sequence;
fusion::for_each(
fusion::zip_view(zipped_sequence(indices, sequence)),
detail::for_each_element_and_slice(range, f));
}
} }