There are two immediate problems with your code:
you compute
fusion::as_nview<N>(*it)
and try to store it as if it were afusion::result_of::as_nview<T::value_type, N>::type
; in truth it is afusion::result_of::as_nview<T::value_type const, N>::type
(*it
has typeT::const_reference
); this is the source of yourconst
-related errors.you try to accumulate the resulting views, but, as far I can tell from the Fusion docs, valid operations on such a view are mostly those of a Fusion Random Access Sequence. In particular you can't add two views together, or default construct one. Here's a lead to a possible fix (by no means the only way though), not actually tested:
typedef typename Container::value_type view_type; typedef typename fusion::result_of::at_c<view_type, 0>::type reference; // boost::decay is from Boost.TypeTraits typedef typename boost::decay<reference>::type value_type; value_type zero = 0; return std::accumulate(container.begin(), container.end(), zero, add_views());
where
add_views
is a functor that returns something in the spirit oflhs + at<0>(rhs)
. Note that this solution only really makes sense if you intend forc
to make views of length exactly one.