Boost logo

Boost Users :

From: Max (LoadCom_at_[hidden])
Date: 2008-05-03 21:12:01


>Max wrote:
>> Hi all
>>
>> I'm wondering if there is such stuff in boost, or anything similar:
>>
>> double d0, d1, d2, d3;
>> boost::array<double &, 4> array = {{d0, d1, d2, d3}};
>> for(int i=0; i<4; i++) array[i] = i;
>> assert(d2 == 2);
>>
>> or
>>
>> double d0, d1, d2, d3;
>> boost::array<double, 4> array;
>> boost::bind(array[0], d0);
>> boost::bind(array[1], d1);
>> boost::bind(array[2], d2);
>> boost::bind(array[3], d3);
>> for(int i=0; i<4; i++) array[i] = i;
>> assert(d2 == 2);
>>
>Sounds like you need the reference wrappers
>http://www.boost.org/doc/libs/1_35_0/doc/html/ref.html which are
>designed for passing references to function objects where passing a
>value would be inappropriate or inefficient, as they are
>CopyConstructible and Assignable they are also suitable for storage in
>containers where simple pointers are inappropriate.
>> Thanks
>> Max
>>

Thank you Somerville for your direction. I never used Ref before, and I'll have
a look into its documentation.

If it won't take a long time, is it possible to rewrite the above code snnipet
making use of boost.Ref?

Thanks again.

Max


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