2012年4月17日火曜日

boost::range 習作 (4)

#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <iostream>


bool hoge( int i, int j, int k ) {
   return (i+j) < k;
}

void hoge_comp( int i, int j, int k, bool& result ) {
  std::cout << i << "+" << j << " < " << k << std::endl;
  result &= hoge( i, j, k );
}

int main(void) {

  int x[] = { 1, 2, 3, 2, 1 };
  int y[] = { 1, 4, 9, 4, 9 };

  bool result = true;
  boost::for_each( x, boost::bind( hoge_comp, _1, 1, 5, boost::ref(result) ) );
  
  std::cout << "result = " << (result ? "true" : "false") << std::endl;

  result = true;
  boost::for_each( y, boost::bind( hoge_comp, _1, 1, 5, boost::ref(result) ) );

  std::cout << "result = " << (result ? "true" : "false") << std::endl;

  return 0;
}

0 件のコメント: