STL container function return values

后端 未结 8 1140
名媛妹妹
名媛妹妹 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:28

    Interesting question. The obvious return value would be the vector (or whatever) that the operation takes place on, so you could then write code like:

    if ( v.push_back(42).size() > n ) {
       // do something
    }
    

    I personally don't like this style, but I can't think of a good reason not to support it.

提交回复
热议问题