Unofficial Hacker News companion — get notified on comment replies, and more.

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

131 points by surprisetalk 6 days ago | lemire.me | 201 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (6)

  1. I feel like this is leaving out the option of only ever referring to objects by a pointer. this means there's no shenanigans around moving or copying things around, and language semantics can still enforce single owners etc. The main disadvantage to this is that it makes any copying explicit, and introduces some (IMO fairly minor) sharp edges around accidentally modifying objects passed into functions etc.
    Replies (1)
    1. It also makes everything heap allocated and prevents dense representations, both of which are not good for performance.
      Replies (2)
      1. Could point to memory from alloca
        Replies (1)
        1. That doesn’t give you the lifetime freedom aspects of the heap, which is what’s required to not think about it.
          Replies (1)
          1. I think what I meant was that in the everything is a pointer model, you can solve the problem you mentioned of only having stuff on the heap by also allowing pointers into the stack. You could even do it automatically based on escape analysis maybe.
      2. you still can have dense representations in many cases, but you're right that it's a much bigger hassle than otherwise and generally requires some type of special casing.

        Still it's a completely valid solution. Like any solution it solves some problems and introduces others.