<small id='7hrqw'></small><noframes id='7hrqw'>

    <tfoot id='7hrqw'></tfoot>

      <bdo id='7hrqw'></bdo><ul id='7hrqw'></ul>

  1. <legend id='7hrqw'><style id='7hrqw'><dir id='7hrqw'><q id='7hrqw'></q></dir></style></legend>
    1. <i id='7hrqw'><tr id='7hrqw'><dt id='7hrqw'><q id='7hrqw'><span id='7hrqw'><b id='7hrqw'><form id='7hrqw'><ins id='7hrqw'></ins><ul id='7hrqw'></ul><sub id='7hrqw'></sub></form><legend id='7hrqw'></legend><bdo id='7hrqw'><pre id='7hrqw'><center id='7hrqw'></center></pre></bdo></b><th id='7hrqw'></th></span></q></dt></tr></i><div id='7hrqw'><tfoot id='7hrqw'></tfoot><dl id='7hrqw'><fieldset id='7hrqw'></fieldset></dl></div>
    2. 如何删除 const_iterator 的常量性?

      How to remove constness of const_iterator?(如何删除 const_iterator 的常量性?)

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

              1. <legend id='v3PUi'><style id='v3PUi'><dir id='v3PUi'><q id='v3PUi'></q></dir></style></legend>
                本文介绍了如何删除 const_iterator 的常量性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                作为这个问题的扩展const_iterators 是否更快?,我还有一个关于 const_iterators 的问题.如何删除 const_iterator 的常量性?虽然迭代器是指针的一般形式,但 const_iteratoriterator 仍然是两个不同的东西.因此,我相信,我也不能使用 const_cast<>const_iterator 转换到 iterators.

                As an extension to this question Are const_iterators faster?, I have another question on const_iterators. How to remove constness of a const_iterator? Though iterators are generalised form of pointers but still const_iterator and iterators are two different things. Hence, I believe, I also cannot use const_cast<> to covert from const_iterator to iterators.

                一种方法可能是您定义一个迭代器,它移动 '直到 const_iterator 指向的元素.但这看起来是一个线性时间算法.

                One approach could be that you define an iterator which moves 'til the element to which const_iterator points. But this looks to be a linear time algorithm.

                知道实现这一目标的最佳方法是什么吗?

                Any idea on what is the best way to achieve this?

                推荐答案

                在 C++11 中有一个具有恒定时间复杂度的解决方案:对于任何序列、关联或无序关联容器(包括所有标准库容器),可以调用range-erase成员函数,范围为空:

                There is a solution with constant time complexity in C++11: for any sequence, associative, or unordered associative container (including all of the Standard Library containers), you can call the range-erase member function with an empty range:

                template <typename Container, typename ConstIterator>
                typename Container::iterator remove_constness(Container& c, ConstIterator it)
                {
                    return c.erase(it, it);
                }
                

                范围擦除成员函数有一对const_iterator 参数,但它们返回一个iterator.因为提供了一个空范围,所以对erase 的调用不会改变容器的内容.

                The range-erase member functions have a pair of const_iterator parameters, but they return an iterator. Because an empty range is provided, the call to erase does not change the contents of the container.

                感谢 Howard Hinnant 和 Jon Kalb 的技巧.

                这篇关于如何删除 const_iterator 的常量性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                Adding types to the std namespace(将类型添加到 std 命名空间)
                Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)

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

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