In C++, is the amortized complexity of std::string

2019-04-08 11:45发布

I know the standard specifies that it is for vectors, but what about strings?

1条回答
唯我独甜
2楼-- · 2019-04-08 12:41

Yes, it is amortized constant time. See table 101 on page 716 of this document:

Table 101 lists operations that are provided for some types of sequence containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized constant time.

Operation      | Description          | Container
---------------+----------------------+----------------------------------
a.push_back(t) | Appends a copy of t. | basic_string, deque, list, vector
查看更多
登录 后发表回答