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

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

      <legend id='Qs81i'><style id='Qs81i'><dir id='Qs81i'><q id='Qs81i'></q></dir></style></legend>

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

        为什么不将向量访问运算符指定为 noexcept?

        Why vector access operators are not specified as noexcept?(为什么不将向量访问运算符指定为 noexcept?)

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

        <tfoot id='4ZqFr'></tfoot>

              <tbody id='4ZqFr'></tbody>

            <small id='4ZqFr'></small><noframes id='4ZqFr'>

                • <bdo id='4ZqFr'></bdo><ul id='4ZqFr'></ul>

                  <legend id='4ZqFr'><style id='4ZqFr'><dir id='4ZqFr'><q id='4ZqFr'></q></dir></style></legend>
                  本文介绍了为什么不将向量访问运算符指定为 noexcept?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么没有指定std::vectoroperator[]frontback成员函数作为 noexcept?

                  Why std::vector's operator[], front and back member functions are not specified as noexcept?

                  推荐答案

                  noexcept 标准的政策是只标记不能不能 失败,但不是那些简单指定不抛出异常的.换句话说,所有具有有限域的函数(传递错误的参数,你会得到未定义的行为)都不是 noexcept,即使它们没有被指定为抛出.

                  The standard's policy on noexcept is to only mark functions that cannot or must not fail, but not those that simply are specified not to throw exceptions. In other words, all functions that have a limited domain (pass the wrong arguments and you get undefined behavior) are not noexcept, even when they are not specified to throw.

                  被标记的函数是诸如 swap(不能失败,因为异常安全通常依赖于它)和 numeric_limits::min(不能失败,返回一个常量原始类型).

                  Functions that get marked are things like swap (must not fail, because exception safety often relies on that) and numeric_limits::min (cannot fail, returns a constant of a primitive type).

                  原因是实现者可能希望提供他们库的特殊调试版本,这些版本会引发各种未定义的行为情况,以便测试框架可以轻松检测到错误.例如,如果您使用带有 vector::operator[] 的越界索引,或者在空的索引上调用 frontback向量.一些实现想要在那里抛出一个异常(他们被允许:因为这是未定义的行为,他们可以做任何事情),但是这些函数上的标准强制noexcept 使这成为不可能.

                  The reason is that implementors might want to provide special debug versions of their libraries that throw on various undefined behavior situations, so that test frameworks can easily detect the error. For example, if you use an out-of-bound index with vector::operator[], or call front or back on an empty vector. Some implementations want to throw an exception there (which they are allowed to: since it's undefined behavior, they can do anything), but a standard-mandated noexcept on those functions makes this impossible.

                  这篇关于为什么不将向量访问运算符指定为 noexcept?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与自定义类对象的向量一起使用?)

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

                    <tbody id='BbOSi'></tbody>

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

                          • <bdo id='BbOSi'></bdo><ul id='BbOSi'></ul>