Thursday, 15 March 2012

c++ - Is the complexity of vector::clear unspecified? -



c++ - Is the complexity of vector::clear unspecified? -

per give-and-take is `std::vector<primitive>::clear()` constant time operation?, noted c++ standard not appear specify running time of vector::clear.

it specifies running time of list::clear (linear; §23.3.5.4.5), .clear both ordered (table 102) , unordered associative containers (table 103) (both linear). however, vector::clear appears missing (though other vector members, .data , .swap appear have specified complexity).

is unspecified, or did miss something?

is unspecified, or did miss something?

yes. @ moment, unspecified.

there open library issue this, text contains link relevant q&a on stackoverflow. reply jonathan wakely question clarifies has been going on.

according linked proposal, complexity requirement of clear() should made linear sequence containers. however, 1 must maintain in mind complexity requirements upper bounds. per paragraph 17.5.1.4/7 of c++11 standard:

complexity requirements specified in library clauses upper bounds, , implementations provide improve complexity guarantees satisfy requirements.

this allows possible optimizations, not mandate them.

even when linked proposal accepted, not allowed assume clear() has o(1) complexity sequence containers of non-class elements, though seems natural , mutual optimization strategy (and reply dasblinkenlight this question on so confirms it).

implementations allowed adopt strategy (per 17.5.1.4/7), won't required so, because in standard such constraint (nor proposed be) specified.

c++ vector language-lawyer

No comments:

Post a Comment