An unofficial, read-only Hacker News reader.

In C++, = default and {} are not the same constructor (opens external site)

129 points by surprisetalk 3 days ago | lemire.me | 198 comments on HN

View full thread · View on Hacker News

Comment thread (3)

  1. I'm not super familiar with Lua so just to make sure I'm understanding you correctly are you referring to to-be-closed variables?

    If so, I think the difference is that in C++/Rust RAII is the default and is quite pervasive as a result. To-be-closed variables seem like IDisposable in C# or try-with-resources in Java in that they allow the programmer to use RAII-like semantics but are opt-in.

    Replies (1)
    1. yes, just like in Rust, where Drop and constructors are optional idioms.
      Replies (1)
      1. Manually implementing the Drop trait, perhaps, but the same can't be said for the drop operation, which you always get at the end of scope unless you opt out (which is very much a rare thing to do).