-
Notifications
You must be signed in to change notification settings - Fork 269
-
C++ Weekly - Ep 108 - Understanding emplace_back
https://www.youtube.com/watch?v=uwv1uvi1OTU
Jason Turner explains in a four minute video how push_back() &
emplace_back() relate to special member functions in C++. I am looking
for an explanation on how pure cpp2 improves/changes any of this.
#include <cstdio>
#include <vector>
struct S{
S(int){ puts("S(int)");}
S(){ puts("S()");}
S(const S&){ puts("S(const S&)");}
S(S&&){ puts("S(S&&)");}
S &operator=(const S &){ puts("S &operator=(const S &)"); return *this;}
S &operator=(S &){ puts("S &operator=(S &)"); return *this;}
~S(){ puts("~S()");} };
int main(){
S s;
// std::vector<S> vec;
// vec.push_back(S());
// vec.emplace_back();
// vec.push_back(S(3));
// vec.emplace_back(3);
}
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I would not expect any changes here, other than how the special member functions are spelled. What kind of improvements or changes would you be expecting to see?
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment