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

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

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

        • <bdo id='ZffiD'></bdo><ul id='ZffiD'></ul>
      1. 为什么不对 std::vector 重载 operator+=() ?

        时间:2023-09-15

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

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

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

                    <tbody id='v2kAq'></tbody>
                1. 本文介绍了为什么不对 std::vector 重载 operator+=() ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经开始学习 C++,所以我不知道在我缺乏知识/经验的情况下,为什么我要描述的对新手来说看起来如此简单的东西在 STL 中还没有.要将向量添加到另一个向量,您必须输入:

                  I've started learning C++, so I don't know in my lack of knowledge/experience why something so seemingly simple to a rookie as what I'm about to describe isn't already in the STL. To add a vector to another vector you have to type this:

                  v1.insert(v1.end(), v2.begin(), v2.end());
                  

                  我想知道在现实世界中人们是否只是重载了 += 运算符以使其不那么冗长,例如

                  I'm wondering whether in the real world people just overload the += operator to make this less verbose, for example to the effect of

                  template <typename T>
                  void operator+=(std::vector<T> &v1, const std::vector<T> &v2) {
                      v1.insert(v1.end(), v2.begin(), v2.end());
                  }
                  

                  那么你就可以了

                  v1 += v2;
                  

                  我也将 push_back 设置为+="一个元素到最后.精通C++的人有什么理由不应该做这些事情或者特别避免做这些事情吗?

                  I also have this set up for push_back to "+=" a single element to the end. Is there some reason these things should not be done or are specifically avoided by people who are proficient in C++?

                  推荐答案

                  这实际上是我希望以 append() 重载形式看到此功能的情况.operator+= 有点歧义,你的意思是将每个向量的元素相加?或者你的意思是追加?

                  This is actually a case where I would like to see this functionality in the form of an overload of append(). operator+= is kinda ambiguous, do you mean to add the elements of each vector to each other? Or you mean to append?

                  然而,就像我说的,我会欢迎:v1.append(v2); 很清楚很简单,我不知道为什么没有.

                  However, like I said, I would have welcomed: v1.append(v2); It is clear and simple, I don't know why it isn't there.

                  这篇关于为什么不对 std::vector 重载 operator+=() ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:向量将所有负值转换为零 下一篇:将一行 csv 文件拆分为 std::vector?

                  相关文章

                  最新文章

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

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

                      <tfoot id='XacyR'></tfoot>
                      <legend id='XacyR'><style id='XacyR'><dir id='XacyR'><q id='XacyR'></q></dir></style></legend>

                    1. <small id='XacyR'></small><noframes id='XacyR'>