简体   繁体   English

使用std :: vector :: begin vs begin(vector)

[英]Use std::vector::begin vs begin(vector)

If I have std::vector (which is a std::vector and will be always a std::vector ). 如果我有std::vector (这是一个std::vector ,它将始终是std::vector )。

Is it superior to use std::begin() instead of std::vector::begin() (or the opposite)? 使用std::begin()代替std::vector::begin()是否更好(或相反)?

Will there be any performance increase/decrease? 性能会有所提高/降低吗?

Example: 例:

std::vector<int> foo(100, 5);
std::sort(foo.begin(), foo.end());        // Case 1
std::sort(std:begin(foo), std::end(foo)); // Case 2

对于“正常” std -container类型std::begin(c)其实是一样的c.begin()

My two pence: 我的两便士:

(which is a std::vector and will be always a std::vector). (这是一个std :: vector,并将始终是std :: vector)。

IMHO this is a guarantee that you cannot make now - this argues for the free function form. 恕我直言,这是您现在不能做的保证-这是自由功能形式的理由。

Is it superior to use std::begin() instead of std::vector::begin() (or the opposite)? 使用std :: begin()代替std :: vector :: begin()是否更好(或相反)?

Only in the sense that the free function form participates in ADL 仅在自由功能形式参与ADL的意义上

Will there be any performance increase/decrease? 性能会有所提高/降低吗?

Not if you enable the optimiser. 如果启用优化器则不行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM