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

2019-04-08 12:17发布

问题:

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

回答1:

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