|
Boost Users : |
Subject: Re: [Boost-users] [multiarray] problems passing views by reference
From: Ronald Garcia (rxg_at_[hidden])
Date: 2010-01-14 16:06:07
Thanks for the contribution Rhys. I think it will make a fine
addition to MultiArray.
Best,
Ron
On Jan 13, 2010, at 11:48 AM, Rhys Ulerich wrote:
>> The problem might be the body of fill_functor for the general
>> case. "*i"
>> will produce a temporary (a subarray), which you are then trying to
>> pass
>> immediately by reference to the smaller fill_functor case. C++
>> doesn't let
>> you pass temporaries by reference, which is a real problem when you
>> need
>> proxy references like MultiArray does. The solution should be as
>> follows:
>>
>> for (typename Array::iterator i = x.begin(); i != x.end(); +
>> +i) {
>> typename Array::iterator::reference ri = *i;
>> f(ri,v);
>> }
>
> Ron's suggestion did fix my problem. Thanks Ron.
>
> Just in case anyone's ever searching for a general MultiArray fill
> implementation, I've attached the now working code/test case.
>
> This might not be a bad example to add to the MultiArray tutorial,
> both
> because it touches on an easy mistake and because people ask about
> fill with some frequency.
>
> - Rhys
> <test_fill.cc>_______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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