std :: string :: substr成员函数的复杂性是什么? [英] What is the complexity of std::string::substr member function?

查看:98
本文介绍了std :: string :: substr成员函数的复杂性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: string :: substr 成员函数的复杂性是什么?是由标准定义还是由实现定义?

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

推荐答案

这是标准所要说明的所有内容:

This is all that standard has to say about it:

n3242,21.4.7.8

n3242, 21.4.7.8

  1. 要求: pos< = size()
  2. 抛出:如果 pos>超出范围,则为 out_of_range .size()
  3. 效果:确定要复制的字符串的有效长度 rlen ,以较小者为准 n size()-pos
  4. 返回: basic_string< charT,traits,Allocator>(data()+ pos,rlen).
  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<charT,traits,Allocator>(data()+pos,rlen).

因此答案是否定的,复杂性未定义.

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

已按照n3242进行了更正,位置>大小而不是位置> =大小

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

这篇关于std :: string :: substr成员函数的复杂性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆