<tfoot id='pv4PB'></tfoot>
  • <i id='pv4PB'><tr id='pv4PB'><dt id='pv4PB'><q id='pv4PB'><span id='pv4PB'><b id='pv4PB'><form id='pv4PB'><ins id='pv4PB'></ins><ul id='pv4PB'></ul><sub id='pv4PB'></sub></form><legend id='pv4PB'></legend><bdo id='pv4PB'><pre id='pv4PB'><center id='pv4PB'></center></pre></bdo></b><th id='pv4PB'></th></span></q></dt></tr></i><div id='pv4PB'><tfoot id='pv4PB'></tfoot><dl id='pv4PB'><fieldset id='pv4PB'></fieldset></dl></div>
        <bdo id='pv4PB'></bdo><ul id='pv4PB'></ul>

        <small id='pv4PB'></small><noframes id='pv4PB'>

        <legend id='pv4PB'><style id='pv4PB'><dir id='pv4PB'><q id='pv4PB'></q></dir></style></legend>
      1. 如何使用 BOOST_FOREACH 同时迭代两个向量?

        时间:2023-07-20
      2. <small id='kAyxV'></small><noframes id='kAyxV'>

          <tfoot id='kAyxV'></tfoot>

              1. <i id='kAyxV'><tr id='kAyxV'><dt id='kAyxV'><q id='kAyxV'><span id='kAyxV'><b id='kAyxV'><form id='kAyxV'><ins id='kAyxV'></ins><ul id='kAyxV'></ul><sub id='kAyxV'></sub></form><legend id='kAyxV'></legend><bdo id='kAyxV'><pre id='kAyxV'><center id='kAyxV'></center></pre></bdo></b><th id='kAyxV'></th></span></q></dt></tr></i><div id='kAyxV'><tfoot id='kAyxV'></tfoot><dl id='kAyxV'><fieldset id='kAyxV'></fieldset></dl></div>
                  <tbody id='kAyxV'></tbody>
                  <bdo id='kAyxV'></bdo><ul id='kAyxV'></ul>
                • <legend id='kAyxV'><style id='kAyxV'><dir id='kAyxV'><q id='kAyxV'></q></dir></style></legend>

                  本文介绍了如何使用 BOOST_FOREACH 同时迭代两个向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用 BOOST FOREACH 复制以下内容

                  I'd like to replicate the following with BOOST FOREACH

                  std::vector<int>::const_iterator i1;
                  std::vector<int>::const_iterator i2;
                  for( i1 = v1.begin(), i2 = v2.begin();
                       i1 < v1.end() && i2 < v2.end();
                       ++i1, ++i2 )
                  {
                       doSomething( *i1, *i2 );
                  }
                  

                  推荐答案

                  同时迭代两件事称为zip"(来自函数式编程),Boost 有一个 zip 迭代器:

                  Iterating over two things simultaneously is called a "zip" (from functional programming), and Boost has a zip iterator:

                  zip 迭代器提供并行迭代多个同时控制序列.构建了一个 zip 迭代器来自迭代器元组.移动 zip 迭代器会移动所有并行迭代器.取消引用 zip 迭代器会返回一个元组包含取消引用各个迭代器的结果.

                  The zip iterator provides the ability to parallel-iterate over several controlled sequences simultaneously. A zip iterator is constructed from a tuple of iterators. Moving the zip iterator moves all the iterators in parallel. Dereferencing the zip iterator returns a tuple that contains the results of dereferencing the individual iterators.

                  请注意,它是一个迭代器,而不是一个范围,因此要使用 BOOST_FOREACH,您必须将其中的两个放入一个 iterator_range 或 pair.所以它不会很漂亮,但稍加注意,你可能会想出一个简单的 zip_range 并编写:

                  Note that it's an iterator, not a range, so to use BOOST_FOREACH you're going to have to stuff two of them into an iterator_range or pair. So it won't be pretty, but with a bit of care you can probably come up with a simple zip_range and write:

                  BOOST_FOREACH(boost::tuple<int,int> &p, zip_range(v1, v2)) {
                      doSomething(p.get<0>(), p.get<1>());
                  }
                  

                  或者 2 的特殊情况并使用 std::pair 而不是 boost::tuple.

                  Or special-case for 2 and use std::pair rather than boost::tuple.

                  我想既然 doSomething 可能有参数 (int&, int&),实际上我们想要一个 tuple.希望它有效.

                  I suppose that since doSomething might have parameters (int&, int&), actually we want a tuple<int&,int&>. Hope it works.

                  这篇关于如何使用 BOOST_FOREACH 同时迭代两个向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <small id='L1gdi'></small><noframes id='L1gdi'>

                • <i id='L1gdi'><tr id='L1gdi'><dt id='L1gdi'><q id='L1gdi'><span id='L1gdi'><b id='L1gdi'><form id='L1gdi'><ins id='L1gdi'></ins><ul id='L1gdi'></ul><sub id='L1gdi'></sub></form><legend id='L1gdi'></legend><bdo id='L1gdi'><pre id='L1gdi'><center id='L1gdi'></center></pre></bdo></b><th id='L1gdi'></th></span></q></dt></tr></i><div id='L1gdi'><tfoot id='L1gdi'></tfoot><dl id='L1gdi'><fieldset id='L1gdi'></fieldset></dl></div>
                  1. <legend id='L1gdi'><style id='L1gdi'><dir id='L1gdi'><q id='L1gdi'></q></dir></style></legend>
                      <bdo id='L1gdi'></bdo><ul id='L1gdi'></ul>

                      • <tfoot id='L1gdi'></tfoot>

                            <tbody id='L1gdi'></tbody>