Has anyone known related reference for such emplace_back usage (C++11)?
void func(const vector <int> &A){
vector <vector <int> > B;
B.emplace_back(A.cbegin() , A.cend()); // emplace vector A directly
}
I'm not sure what your real question is, but the code you have shown inserts a new vector in-place inside B
. The new vector is initialized by calling its constructor (4) which takes the two arguments A.cbegin() , A.cend()
.
You can think of it as an optimized version of
B.push_back(std::vector<int>(A.cbegin() , A.cend()));
You'd better searched them on Google or cppreference.com before asking for any further reference.
emplace_back()
: http://en.cppreference.com/w/cpp/container/vector/emplace_backcbegin()/cend()
(since C++11): they are same withbegin()/end()
http://en.cppreference.com/w/cpp/container/vector/begin