Boost logo

Boost Users :

Subject: [Boost-users] [lambda] Can't quite get the hang of it!
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-12-05 07:19:21


Starting with this...

for( j = joff; j < joff + 8; j++)
  for( i = ioff; i < ioff + 8; i++)
    img->m7[j][i] = iClip1(img->max_imgpel_value,
(img->m7[j][i]+(long)mpr[j][i]));

I'd like to move as much of the loop invariance out of the loop as I can.
So I tried this...

using boost :: lambda :: _1;
using boost :: lambda :: _2;

int ilast = ioff + 8;
int jlast = joff + 8;

boost :: function< int( int &, int ) > clip =
  _1 = boost :: lambda :: bind( iClip1, img -> max_imgpel_value, _1 + _2 );

for( j = joff; j != jlast; ++ j )
  for( i = ioff; i != ilast; ++ i )
    clip( img -> m7[j][i], mpr[j][i] );

Which works, but I'd like the nested clip function to be fn( i, j ), so I
tried this...

boost :: function< void( int, int ) > clip2 =
  boost :: lambda :: bind( clip, img -> m7[ _2 ][ _1 ], mpr[ _2 ][ _1 ] );

for( j = joff; j != jlast; ++ j )
  for( i = ioff; i != ilast; ++ i )
    clip2( i, j );

Which doesn't work. I think I need some boost::refs around the arrays I'm
subscripting,
but I can't quite seem to get it right.

Error is...

loop.cpp:50: error: no match for 'operator[]' in
'img->img_par::m7[boost::lambda::<unnamed>::_2]'
loop.cpp:50: error: no match for 'operator[]' in
'mpr[boost::lambda::<unnamed>::_2]'
loop.cpp:50: error: `bind' undeclared (first use this function)

Any thoughts?

Thanks, Rob.



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