STL container function return values

后端 未结 8 1151
名媛妹妹
名媛妹妹 2021-01-05 03:41

When looking over the member functions of the STL containers, an odd thought occurred to me. Why don\'t functions like std::vector::push_back(T) not ha

8条回答
  •  星月不相逢
    2021-01-05 04:39

    Maybe because it was not "needed"?

    erase() and insert() have no other way than return an iterator to allow continuing a loop it was called in.

    I don't see a good reason to support the same logic with push_back().

    But sure, it would be be wonderful to make more cryptic expressions. (I don't see an improvement in your example, it looks like a good way to slow your coworkers when reading your code...)

提交回复
热议问题