Why vector access operators are not specified as noexcept?

前端 未结 3 1947
南笙
南笙 2020-12-05 02:05

Why std::vector\'s operator[], front and back member functions are not specified as noexcept?

3条回答
  •  执念已碎
    2020-12-05 02:28

    In short, there are functions specified with or without noexcept. It is intended, because they are different. The principle is: a function with undefined behavior specified (e.g. due to improper arguments) should not be with noexcept.

    This paper explicitly specified these members being without noexcept. Some members of vector were used as examples:

    Examples of functions having wide contracts would be vector::begin() and vector::at(size_type). Examples of functions not having a wide contract would be vector::front() and vector::operator[](size_type).

    See this paper for initial motivation and detailed discussion. The most obvious realistic problem here is testability.

提交回复
热议问题