繁体   English   中英

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

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

如果我有std::vector (这是一个std::vector ,它将始终是std::vector )。

使用std::begin()代替std::vector::begin()是否更好(或相反)?

性能会有所提高/降低吗?

例:

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()

我的两便士:

(这是一个std :: vector,并将始终是std :: vector)。

恕我直言,这是您现在不能做的保证-这是自由功能形式的理由。

使用std :: begin()代替std :: vector :: begin()是否更好(或相反)?

仅在自由功能形式参与ADL的意义上

性能会有所提高/降低吗?

如果启用优化器则不行。

暂无
暂无

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

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