Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

c++ - Copy/move constructor elision

Not sure whether Section 12.8 #31.3

[...] copy elision, is permitted in the following circumstances (which may be combined to eliminate multiple copies):

when a temporary class object that has not been bound to a reference ([class.temporary]) would be copied/moved to a class object with the same cv-unqualified type, the copy/move operation can be omitted by constructing the temporary object directly into the target of the omitted copy/move [...]

applies to following:

class A {
   public:
     A() {}
     A(const A&) = delete;
     A(A&&) { printf("move"); }
};

void foo(A a) {}

int main() {
  A a;
  foo(std::move(a));
}

Is elision allowed in this case? I want to ensure a is moved from.

question from:https://stackoverflow.com/questions/65910443/copy-move-constructor-elision

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...