views:

67

answers:

3

I implemented an iterator, which has Fibonacci numbers as output. In my main() I'd like to find a number which is dividable by 17 (it's 34). Why doesn't work my find_if statement.

Thank you!

  #include <boost/operators.hpp>
  #include <algorithm>
  #include <tr1/functional>

    struct FibIter: boost::input_iterator_helper<FibIter,unsigned long long> {

 //typedef value_type unsigned long long;
 FibIter(value_type l=0):counter(0), fib0(0),fib1(1){
  while(l!=counter)
   ++(*this);
 }

 value_type operator*() const {return fib0;}
 FibIter& operator++() {
  ++counter; 
  value_type fnew = fib0+fib1;
  fib0 = fib1;
  fib1 = fnew;
  return *this;
  }
 bool operator==(FibIter const &other)const {
  return counter == other.counter;
 }


    private:
 value_type counter;
 value_type fib0, fib1;
    };

    using namespace std;
    using namespace tr1;
    using namespace placeholders;

    int main() {
 FibIter found = find_if(FibIter(), FibIter(100),bind(not2(modulus<unsigned long long>()),_1,17ULL));
    }
A: 
bind(not2(modulus<unsigned long long>()),_1,17ULL)

should be

not1(bind(modulus<unsigned long long>(),_1,17ULL))
Alexandre C.
I tried it, but it doesn't work...
melbic
A: 

I think if you start from first number which is 0, find will return it (modulus(0,17) = 0).

mho
ok thats true, but thats not the point.
melbic
A: 

Ok I solved it by using !boost::bind(...) instead of tr1::bind.

melbic