Why not overload operator+=() for std::vector?

前端 未结 4 1784
别那么骄傲
别那么骄傲 2020-12-06 16:18

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 i

4条回答
  •  庸人自扰
    2020-12-06 16:54

    I think the main reason is that the semantics of += aren't obvious. There's the meaning that you have here, but there's also an equally valid meaning, which is element-wise addition of each element of equal-sized vectors. Due to this ambiguity I assume they decided it was better to rely on the user to call insert diretly.

提交回复
热议问题