Why isn't std::string::max_size a compile-time constant?

后端 未结 4 1219
情书的邮戳
情书的邮戳 2021-01-03 18:22

std::string provides a max_size() method to determine the maximum number of elements it can contain.

However, to work out the maximum lengt

4条回答
  •  一整个雨季
    2021-01-03 18:41

    One reason is that the max_size function isn't very useful at all, and the committee doesn't think it is worth the trouble to try to fix it. So it is just left the way it is, because it is part of the documented interface.

    See library defect report #197:

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3440.html#197

    max_size() isn't useful for very many things, and the existing wording is sufficiently clear for the few cases that max_size() can be used for. None of the attempts to change the existing wording were an improvement.

提交回复
热议问题