C++: why this simple Scope Guard works?

后端 未结 1 474
说谎
说谎 2021-01-04 23:14

Every looked at scope guard so far has a guard boolean variable. For example, see this discussion: The simplest and neatest c++11 ScopeGuard

But a simple guard works

相关标签:
1条回答
  • 2021-01-04 23:27

    You're observing the effects of Copy Elision (or Move Elision, in this case). Copy Elision is not guaranteed / mandatory, but usually performed by major compilers even when compiling w/o optimizations. Try gcc's -fno-elide-constructors to see it "break": http://melpon.org/wandbox/permlink/B73EuYYKGYFMnJtR

    0 讨论(0)
提交回复
热议问题