Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Warning:</strong> <code>boost::zip_iterator</code> and <code>boost::combine</code> as of Boost 1.63.0 (2016 Dec 26) will cause undefined behavior if the length of the input containers are not the same (it may crash or iterate beyond the end).</p> <hr> <p>Starting from Boost 1.56.0 (2014 Aug 7) you could <a href="http://www.boost.org/doc/libs/release/libs/range/doc/html/range/reference/utilities/combine.html" rel="noreferrer">use <code>boost::combine</code></a> (the function exists in earlier versions but undocumented):</p> <pre><code>#include &lt;boost/range/combine.hpp&gt; #include &lt;vector&gt; #include &lt;list&gt; #include &lt;string&gt; int main() { std::vector&lt;int&gt; a {4, 5, 6}; double b[] = {7, 8, 9}; std::list&lt;std::string&gt; c {"a", "b", "c"}; for (auto tup : boost::combine(a, b, c, a)) { // &lt;--- int x, w; double y; std::string z; boost::tie(x, y, z, w) = tup; printf("%d %g %s %d\n", x, y, z.c_str(), w); } } </code></pre> <p>This would print </p> <pre> 4 7 a 4 5 8 b 5 6 9 c 6 </pre> <hr> <p>In earlier versions, you could define a range yourself like this:</p> <pre><code>#include &lt;boost/iterator/zip_iterator.hpp&gt; #include &lt;boost/range.hpp&gt; template &lt;typename... T&gt; auto zip(T&amp;&amp;... containers) -&gt; boost::iterator_range&lt;boost::zip_iterator&lt;decltype(boost::make_tuple(std::begin(containers)...))&gt;&gt; { auto zip_begin = boost::make_zip_iterator(boost::make_tuple(std::begin(containers)...)); auto zip_end = boost::make_zip_iterator(boost::make_tuple(std::end(containers)...)); return boost::make_iterator_range(zip_begin, zip_end); } </code></pre> <p>The usage is the same.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload