1. <tfoot id='ORcHj'></tfoot>

          <bdo id='ORcHj'></bdo><ul id='ORcHj'></ul>
      2. <small id='ORcHj'></small><noframes id='ORcHj'>

      3. <i id='ORcHj'><tr id='ORcHj'><dt id='ORcHj'><q id='ORcHj'><span id='ORcHj'><b id='ORcHj'><form id='ORcHj'><ins id='ORcHj'></ins><ul id='ORcHj'></ul><sub id='ORcHj'></sub></form><legend id='ORcHj'></legend><bdo id='ORcHj'><pre id='ORcHj'><center id='ORcHj'></center></pre></bdo></b><th id='ORcHj'></th></span></q></dt></tr></i><div id='ORcHj'><tfoot id='ORcHj'></tfoot><dl id='ORcHj'><fieldset id='ORcHj'></fieldset></dl></div>
        <legend id='ORcHj'><style id='ORcHj'><dir id='ORcHj'><q id='ORcHj'></q></dir></style></legend>
      4. const_iterator 和 iterator 有什么区别?

        时间:2024-05-11
          <tbody id='NmU2y'></tbody>
          1. <i id='NmU2y'><tr id='NmU2y'><dt id='NmU2y'><q id='NmU2y'><span id='NmU2y'><b id='NmU2y'><form id='NmU2y'><ins id='NmU2y'></ins><ul id='NmU2y'></ul><sub id='NmU2y'></sub></form><legend id='NmU2y'></legend><bdo id='NmU2y'><pre id='NmU2y'><center id='NmU2y'></center></pre></bdo></b><th id='NmU2y'></th></span></q></dt></tr></i><div id='NmU2y'><tfoot id='NmU2y'></tfoot><dl id='NmU2y'><fieldset id='NmU2y'></fieldset></dl></div>
              <bdo id='NmU2y'></bdo><ul id='NmU2y'></ul>

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

              1. <legend id='NmU2y'><style id='NmU2y'><dir id='NmU2y'><q id='NmU2y'></q></dir></style></legend>

                • <tfoot id='NmU2y'></tfoot>
                  本文介绍了const_iterator 和 iterator 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这两者在 STL 内部实现有什么区别.性能有什么区别?我想当我们以只读方式"遍历向量时,我们更喜欢 const_iterator,对吧?

                  What is difference between these two regarding implementation inside STL. what is the difference regarding performance? I guess when we are traversing the vector in "read only wise", we prefer const_iterator, right?

                  谢谢.

                  推荐答案

                  没有性能差异.

                  const_iterator 是一个指向 const 值的迭代器(就像一个 const T* 指针);取消引用它返回对常量值的引用(const T&)并防止修改引用的值:它强制执行 const-正确性.

                  A const_iterator is an iterator that points to const value (like a const T* pointer); dereferencing it returns a reference to a constant value (const T&) and prevents modification of the referenced value: it enforces const-correctness.

                  当你有一个const引用容器时,你只能得到一个const_iterator.

                  When you have a const reference to the container, you can only get a const_iterator.

                  我提到const_iterator 返回常量指针"这是不准确的,感谢 Brandon 指出.

                  Edited: I mentionned "The const_iterator returns constant pointers" which is not accurate, thanks to Brandon for pointing it out.

                  对于 COW 对象,获取非常量迭代器(或取消引用它)可能会触发复制.(std::string 的一些过时和现在不允许的实现使用 COW.)

                  For COW objects, getting a non-const iterator (or dereferencing it) will probably trigger the copy. (Some obsolete and now disallowed implementations of std::string use COW.)

                  这篇关于const_iterator 和 iterator 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么我不能用 std::unordered_map 替换 std::map 下一篇:复制 std::vector:更喜欢赋值还是 std::copy?

                  相关文章

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

                    <small id='9Rw4e'></small><noframes id='9Rw4e'>

                  1. <tfoot id='9Rw4e'></tfoot>
                      <legend id='9Rw4e'><style id='9Rw4e'><dir id='9Rw4e'><q id='9Rw4e'></q></dir></style></legend>

                      • <bdo id='9Rw4e'></bdo><ul id='9Rw4e'></ul>