|
Boost Users : |
Subject: [Boost-users] [range] Zip range adaptor
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2011-01-22 18:21:51
All,
I've been using the boost range library for a few months now, and it's
simplified my life considerably.
I occasionally want to use something akin to MPL's zip_view and
unpack_args with my ranges. For example:
<code>
const std::vector<int> vec1 = list_of(1)(2)(3)(4)(5)(6);
std::vector<int> vec2 = list_of(10)(20)(30)(40)(50)(60);
std::vector<int> vec3 = list_of(100)(200)(300)(400)(500)(600);
boost::for_each(zip(vec1, vec2, vec3) | strided(2), unpack(
std::cout << px::val('(') << arg1 <<", "<< arg2 <<", "<< arg3 << ")\n"));
boost::transform(vec1, boost::begin(zip(vec3, vec2)),
px::construct<boost::tuple<int,int> >(arg1 + 1, arg1 + 2));
boost::for_each(zip(vec2, vec3),
unpack(std::cout << px::val('(') << arg1 << ", " << arg2 << ")\n"));
</code>
I note that the new algorithms include a two-argument for_each, but it
would be nice to have something more extensible. I may have missed it
in the documentation or on the list, but I haven't found anything like
that. Does anyone know of such an adaptor?
Since it's the weekend, I actually implemented code which allows the
previous snippet to compile -- if no such adaptor exists I'd be happy
to make it available/submit it to boost assuming there's interest.
Thanks,
Nate
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