Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] transform & iterators
From: David A. Greene (greened_at_[hidden])
Date: 2010-03-12 00:55:41


On Thursday 11 March 2010 11:39:10 Steven Watanabe wrote:

> > Ugh. That makes things difficult then. There's no simple way to define
> > a function that just takes a pair of iterators and does something with
> > them. Surely others have tried to do things like this before. What's
> > the typical solution?
>
> Use a recursive function template or use one of fusion's algorithms.

But the non-compiling example in the first testcase shows that a fusion
algorithm doesn't provide a general solution. The sequence could be the
result of an application of transform() or some other algorithm that causes
problems. Unless there's some other technique I've missed.

In any case, I wasn't completely clear about what my goal is. Ultimately
I'd like to initialize a class with a pair of iterators:

struct foo {
  vector<int> data;

  template<typename InputIterator>
  foo(InputIterator begin, InputIterator end) : data(begin, end) {}
};

foo could be initialized from many different kinds of sources:

vector<int> mydata;
foo f(mydata.begin(), mydata.end());

fusion::vector<int, int, int, int> mydata(1,2,3,4);
foo f(fusion::begin(mydata), fusion::end(mydata));

Unfortunately, it appears this isn't possible and foo will need at least two
constructors:

struct foo {
  vector<int> data;

  template<typename InputIterator>
  foo(InputIterator begin, InputIterator end) : data(begin, end) {}

  template<typename Sequence>
  foo(Sequence d) {
    // Some fusion algorithm
  }
};

But that doesn't seem to be a general solution either due to the
transform() problem described above.

                                        -Dave


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