I have watched the talk Danila Kutenin — C++ STL best and worst performance features (including one other version of the same talk), I have read the blog, but I still do not understand what is preventing optimization of std::pair assignment operator.
godbolt link of the comparison with custom pair, code inlined here:
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());
}