I know that it is std::list::operator[]not implemented, since it has poor performance. But what about std::vector::insert, it is as inefficient as it is std::list::operator[]. What is the explanation?
std::list::operator[]
std::vector::insert
std::vector::insertis implemented because it std::vectormust satisfy the requirements of the SequenceContainer concept , and is operator[]not required by any concepts (which I know), it is possible that it will be added to the concept ContiguousContainerin C ++ 17. Thus, it is operator[]added to containers that can be used as arrays, while it insertis required according to the specification of the interface, so containers that correspond to a specific concept can be used in general algorithms.
std::vector
operator[]
ContiguousContainer
insert
, , . , , , . , , , , , .
operator[], , , ( , vector). insert . , , vector, , . , . insert, ( , ). .
vector
, operator[] , .
std::list::operator[] O (N) , list. operator[], . ++ a [], O (1) (, , O (Log N)). [] list .
list
[]
std::vector::insert O (N), : vector . , .
[] . ( ) . , .
auto a = Container [10]; // Ideally I can assume this is quick
std::list <>::operator [] std::next <std::list<>::iterator>. cpp-reference.
std::list <>::operator []
std::next <std::list<>::iterator>
auto a = *std::next (Container.begin (), 10); // This may take a little while
. , , , .
Source: https://habr.com/ru/post/1650323/More articles:Failed to install Statsmodels ... python - pythonSSRS Remove XML header from SOAP message - soapWhy is GDI + over-consuming memory when working with fonts in Windows 10? - c #Html5 routing using Spring and Angular - javaSetting the Django Debug toolbar: TypeError: __init __ () takes 1 positional argument, but 2 are given - django-debug-toolbarConfiguring virtualenv using Paramiko SSH - pythonUse T-SQL with conditional logic to override column values for use in SQL Server view - sqlПочему создается ArrayList с начальной мощностью медленно? - javaИзменение порядка элементов гибкости при изменении ширины коробки - javascriptPHP simple html DOM removes all attributes from html tag - htmlAll Articles