[iterator] transform_iterator

Hello
I just came across transform_iterator and found it a useful generic tool.
But is it possible for it to go further to make the following code get
compiled and run as expected?
struct A
{
int i_;
A() : i_(0) {}
explicit A(int i) : i_(i) {}
};
const int N = 5;
A a_list[N] = { A(-3), A(1), A(3), A(2), A(-4) };
typedef boost::function

AMDG Max wrote:
I just came across transform_iterator and found it a useful generic tool. But is it possible for it to go further to make the following code get compiled and run as expected?
No.
struct A { int i_; A() : i_(0) {} explicit A(int i) : i_(i) {} };
const int N = 5; A a_list[N] = { A(-3), A(1), A(3), A(2), A(-4) };
typedef boost::function
fn_t; // sorting a_list according to the elements' i_ member std::stable_sort(boost::make_transform_iterator(a_list, fn_t(boost::bind(&A::i_, _1))), boost::make_transform_iterator(a_list+N, fn_t(boost::bind(&A::i_, _1))), std::less<int>());
stable_sort assumes that the sort keys are the same as the objects that it is moving around. In Christ, Steven Watanabe
participants (2)
-
Max
-
Steven Watanabe