An unofficial, read-only Hacker News reader. Join the beta →

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

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

View full thread · View on Hacker News

Comment thread (2)

  1. Fair.

    I think guaranteed in-place initialization is probably the strongest example of something that cannot be expressed through From or Default alone. There are proposals to solve this via traits. I haven't dug deep enough into them, but I'd assume those would be "special" traits that rely on compiler-provided semantics not otherwise expressible in ordinary library code.

    Right now, both Box::new() and the vec![] macro resort to compiler intrinsics (write_via_move and write_box_via_move), particularly to avoid unnecessary intermediate storage and excessive stack usage.

    Replies (1)
    1. At least from what I can remember the work is in an early enough stage that multiple proposals being considered. IIRC dedicated syntax is in the cards as well.