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

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

        <tfoot id='faP6V'></tfoot>
      1. <legend id='faP6V'><style id='faP6V'><dir id='faP6V'><q id='faP6V'></q></dir></style></legend>
      2. 容量是否复制到向量中?

        时间:2023-10-07

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

          <tfoot id='ygbBX'></tfoot>
        1. <small id='ygbBX'></small><noframes id='ygbBX'>

            • <legend id='ygbBX'><style id='ygbBX'><dir id='ygbBX'><q id='ygbBX'></q></dir></style></legend>
              • <bdo id='ygbBX'></bdo><ul id='ygbBX'></ul>
                  <tbody id='ygbBX'></tbody>

                  本文介绍了容量是否复制到向量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  输入以下代码:

                  std::vector<int> a;
                  a.reserve(65536);
                  std::vector<int> b(a);  //NOTE: b is constructed from a
                  
                  a.reserve(65536); // no reallocation
                  b.reserve(65536);
                  

                  是否复制了容量?最后一行会重新分配吗?标准对此是否有任何说明或沉默?

                  Is capacity copied? Will there be a reallocation on the last line? Does the standard say anything about this or is it silent?

                  推荐答案

                  是否复制了容量?

                  Is capacity copied?

                  在实践中,没有.我在 Clang 和 GCC 以及 MSVC 并且它们都没有复制容量.

                  In practice, no. I tested it online in Clang and GCC as well as MSVC and none of them copy the capacity.

                  最后一行会重新分配吗?

                  Will there be a reallocation on the last line?

                  如果容量小于要保留的参数(即它不会被复制),则是.

                  If the capacity is less than the argument to reserve (i.e. it doesn't get copied) then yes.

                  标准对此有说明还是沉默?

                  Does the standard say anything about this or is it silent?

                  vector.cons 中没有提供复制构造函数的定义.相反,我们必须查看 container.requirements

                  No definitions for the copy constructor are provided in vector.cons. Instead we have to look at the container.requirements

                  X 表示包含 Taa 类型对象的容器类b 表示 X 类型的值,u 表示一个标识符,r 表示X 类型的非常量值,并且 rv 表示的非常量值输入 X.

                  X denotes a container class containing objects of type T, a and b denote values of type X, u denotes an identifier, r denotes a non-const value of type X, and rv denotes a non-const rvalue of type X.

                  X u(a)

                  X u = a;

                  要求: TCopyInsertableX(见下文).

                  Requires: T is CopyInsertable into X (see below).

                  发布:u == a

                  现在两个容器相等是什么意思?

                  Now what does it mean for two containers to be equal?

                  a == b

                  == 是一个等价关系.equal(a.begin(), a.end(), b.begin(), b.end())

                  换句话说,既然不需要capacity在比较中相等,那么就没有理由复制capacity.

                  In other words, since it doesn't require capacity to be equal in the comparison, then there's no reason to copy the capacity.

                  这篇关于容量是否复制到向量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从 C++ std::vector 中删除元素 下一篇:vector 的复制/移动分配后底层存储会发生什么变化

                  相关文章

                  最新文章

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

                      <bdo id='QP5aT'></bdo><ul id='QP5aT'></ul>

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

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