6 #ifndef ECHELON_DETAIL_MAP_INDICES_HPP 7 #define ECHELON_DETAIL_MAP_INDICES_HPP 12 #include <initializer_list> 15 #include <boost/iterator/zip_iterator.hpp> 16 #include <boost/tuple/tuple.hpp> 23 template <
typename... IndexTypes>
24 inline std::size_t map_indices(
const std::vector<std::size_t>& shape, IndexTypes... indices)
26 assert(shape.size() ==
sizeof...(indices));
28 const std::initializer_list<std::size_t> indices_ = {
static_cast<std::size_t
>(indices)...};
30 auto first = boost::make_zip_iterator(boost::make_tuple(begin(shape), begin(indices_)));
31 auto last = boost::make_zip_iterator(boost::make_tuple(end(shape), end(indices_)));
33 return std::accumulate(first, last, static_cast<std::size_t>(0),
34 [](std::size_t acc,
const boost::tuple<std::size_t, std::size_t>& value)
35 {
return boost::get<0>(value) * acc + boost::get<1>(value); });
echelon's core namespace
Definition: attribute.cpp:10