【发布时间】:2020-11-23 23:46:49
【问题描述】:
我看过Danila Kutenin — C++ STL best and worst performance features 的演讲(包括同一演讲的另一个版本),我已经阅读了blog,但我仍然不明白是什么阻碍了 std::pair 赋值运算符的优化。
godbolt link of the comparison with custom pair,此处内联代码:
struct MyPair {
int a;
int b;
};
// slower
void CopyPair(const std::vector<std::pair<int, int>>& a,
std::vector<std::pair<int, int>>& b) {
std::copy(a.begin(), a.end(), b.begin());
}
// faster
void SmartCopyPair(const std::vector<MyPair>& a,
std::vector<MyPair>& b) {
std::copy(a.begin(), a.end(), b.begin());
}
【问题讨论】:
-
您能总结一下您的期望/您正在展示的内容吗?我不倾向于通过外部链接来了解 SO 问题的要点。
标签: c++ stl compiler-optimization