Is there a design reason why std::set doesnt have front and back member functions?

后端 未结 1 1637
梦如初夏
梦如初夏 2021-02-07 07:37
  1. I know I can use *s.begin(), but same argument can be used for vector, which has front/back
  2. often I use the or
相关标签:
1条回答
  • 2021-02-07 08:13

    I imagine that the words "front" and "back" are reserved for sequence containers (i.e. those where the order of elements is determined by the order of insertion), and the words are meant to suggest a physical position in that sequence.

    Since set is not a sequence container (but instead an associative container), this isn't appropriate. In particular, note that the meaning of "front" can change by later insertions of an unrelated element.

    0 讨论(0)
提交回复
热议问题