Boost logo

Boost Users :

From: Nicola (nvitacolonna_at_[hidden])
Date: 2008-04-11 05:10:42


Hello,
I cannot figure out why the following code is wrong:

#include <iostream>
#include <vector>
#include <functional>
#include <boost/iterator/transform_iterator.hpp>

struct f : public std::unary_function<int, int&> {
   int& operator()(int& x) { return x; }
};

typedef std::vector<int> vec_type;
typedef boost::transform_iterator<f, vec_type::iterator> trans_iter_type;

int main() {
   vec_type V;
   V.push_back(4);
   trans_iter_type it(boost::make_transform_iterator(V.begin(), f()));
   std::cout << *it << std::endl;
   *it = 8;
   std::cout << *it << std::endl;
   return 0;
}

The compiler (g++ 4.0.1) complains about dereferencing and the error
message says:

error: passing ‘const f’ as ‘this’ argument of ‘int&
f::operator()(int&)’ discards qualifiers

Nicola


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