簡體   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