Boost logo

Boost Users :

From: Ravi (lists_ravi_at_[hidden])
Date: 2008-05-05 09:58:51


On Saturday 03 May 2008 09:12:01 pm Max wrote:
> >>      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);

[snip]

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

#include <boost/array.hpp>
#include <boost/ref.hpp>

#include <cassert>

int main()
{
  typedef boost::reference_wrapper<double> double_ref_t;
  boost::array<double, 2> 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 );
}


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