|
Boost Users : |
Subject: [Boost-users] [multiarray] problems passing views by reference
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2010-01-05 23:23:30
Recently, Hanan Sadar asked about a multi_array fill implementation
[1]. The standard std::fill_n(x.data(),x.num_elements(),v) answer
only works when x is a boost::multi_array or boost::multi_array_ref
but does not handle the general MultiArray concept.
I decided to implement an arbitrary dimensional MultiArray fill
capable of handling such views correctly. It's been absolutely
miserable for reasons I don't understand but which resemble comments
from James Amundson's recent thread [2]. Attached is my attempt with
two exasperating lines marked by "Cannot use reference, why?".
For a non-multi_array, non-multi_array_ref instance (i.e. a view)
using a signature like
template< class Array, class V > void operator()(Array x, const V &v);
allows the code to compile and operate correctly. However, it incurs
pass-by-value overhead. Using
a signature like
template< class Array, class V > void operator()(Array &x, const V &v);
using pass-by-reference dies at compilation time. All of my attempts
to use MultiArray's associated typedefs die, including hours of
mucking with MultiArray::reference.
What am I missing here? Why can't I pass a general MultiArray view
type by reference?
- Rhys
[1] http://groups.google.com/group/boost-list/browse_thread/thread/829ebea7fef28db0/57485403b4e809dc
[2] http://groups.google.com/group/boost-list/browse_thread/thread/4531a7c35a5865fc/6fdec1189d01acde
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net