AMDG
Matthias Vallentin wrote:
I think the easiest way is probably to create a runtime
iterator that walks over the vector and recurses into
any variants that it contains.
Then you can use fusion's
algorithms to iterate over the fusion::vector and the
vector in parallel.
I'm not sure if I can follow. If I start with the variant and have some
plan to partition it into sequences, how would I use an iterator rather
a visitor? Would you mind illustrating your idea with a small code
snippet?
Actually making an iterator is rather a pain. It's probably easiest to copy
the variant into a flattened vector like this.
#include
#include <vector>
#include <algorithm>
template<class Iter>
class visitor {
public:
typedef void result_type;
visitor(Iter& iter) : out(&iter) {}
template<class T>
void operator()(T& t) const {
*(*out)++ = &t;
}
template<class T>
void operator()(std::vector<T>& v) const {
std::for_each(v.begin(), v.end(), boost::apply_visitor(*this));
}
Iter* out;
};
template
Iter flatten_variant(V& v, Iter out) {
boost::apply_visitor(visitor<Iter>(out), v);
return out;
}
int main() {
boost::make_recursive_variant<
int,
double,
std::vectorboost::recursive_variant_
>::type v;
std::vector > temp;
flatten_variant(v, std::back_inserter(temp));
}
In Christ,
Steven Watanabe