How should a size-limited stl-like container be implemented?

前端 未结 6 1864
生来不讨喜
生来不讨喜 2020-12-07 04:09

While refactoring, I wanted to change an array where entries are added to an std::vector, but for compatibility (persistency, downgrading,...), it still needs to have an upp

6条回答
  •  执笔经年
    2020-12-07 04:36

    Customize the vector class to impose an upper limit. Probably, you can have a new api exposed which will check the size against the upper limit and return false if exceeds otherwise call the regular insertion method.

提交回复
热议问题