What is the complexity of std::string::substr member function?

前端 未结 3 767
悲&欢浪女
悲&欢浪女 2020-12-18 07:37

What is the complexity of std::string::substr member function? Is it defined by standard or implementation-defined?

3条回答
  •  执笔经年
    2020-12-18 07:43

    This is all that standard has to say about it:

    n3242, 21.4.7.8

    1. Requires: pos <= size()
    2. Throws: out_of_range if pos > size()
    3. Effects: Determines the effective length rlen of the string to copy as the smaller of n and size() - pos
    4. Returns: basic_string(data()+pos,rlen).

    So the answer would be no, the complexity is not defined.

    EDIT: Corrected as per n3242, pos > size not pos >= size

提交回复
热议问题