Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

push_back() & emplace_back() relate to special member functions #1292

Unanswered
cwhii asked this question in Q&A
Discussion options

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); 
}
You must be logged in to vote

Replies: 1 comment

Comment options

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?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /