
#include
#include #include <cassert>
int main() { typedef boost::reference_wrapper<double> double_ref_t; boost::array
array; double_ref_t d0( array[0] ); double_ref_t d1( array[1] );
array[0] = 1.0; array[1] = 2.0; assert( d1 == 2.0 );
d0 += d1; assert( d0 == 3.0 ); }
Thank you for your reply, I've also walked through the brief documentation
of Ref (There's even not a simple example showing its usage and power!)
The solution you provided is nearly what I need. My main intention is to get
the ability to group/organize scattered/individual variables of a same type
into a standard container (vector or so) to enable fast/elegant traversal in
one run with one or two lines of code (with a call to for_each() or similar),
without doing the same operation one by one with these individual variables.
With your solution, I should declare my varaibles of type T, on which I will
do some operation in the future, as boost::reference_wrapper<T>. Obviously
to me for any arbitrary type, class reference_wrapper<T> will not automatically
delegate all the functionality of T. That's why I'm not saying this is EXACTLY
what I need. And remember to delcare T as reference_wrapper<T> for a variable
is an extra burden to me. :-)
In the meantile, your code is no different to the following much simpler form:
boost::array