Boost logo

Boost Users :

From: Bill Somerville (bill_at_[hidden])
Date: 2008-05-05 21:28:12


Max wrote:
>> #include <cassert>
>> #include <boost/array.hpp>
>> #include <boost/ref.hpp>
>>
>> int main()
>> {
>> double d0, d1, d2, d3;
>> boost::array<boost::reference_wrapper<double>, 4> array =
>> {boost::ref(d0), boost::ref(d1), boost::ref(d2), boost::ref(d3)};
>> for(int i=0; i<4; i++)
>> {
>> array[i].get() = i;
>> }
>> assert(d2 == 2);
>>
>> return 0;
>> }
>>
>
> Thank you Somerville for your solution. This is exactly what I need!
>
>
>> although this is a slightly unusual construct which might suffer nasty
>> aliasing issues, perhaps a few more details of your requirement might
>> clarify a better approach.
>>
>
> Please decorate on the 'nasty aliasing issues'. For more details of my
> intention, please refer to my previous mail I just posted. I hope ther's
> a even more elgent way to get rid of the issues you mentioned.
>
Given your requirement then this does seem a fairly good solution. I was
just pointing out that you will have to ensure that the lifetime of the
objects being bound to the reference wrappers are at least as long as
the reference wrappers themselves. This is no different than references
or pointers.
> B/Rgds
> Max
>

-- 
Bill Somerville
Class Design Limited


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