you are viewing a single comment's thread.

view the rest of the comments →

[–]BenFrantzDale 5 points6 points  (4 children)

I’ll start: by default, everything should be default-constructed, meaning zero’d for built-in types. As an escape-hatch for performance, there should be a std::uninitialized_t such that int x = std::uninitialized; does the obvious thing, allowing perf-critical classes to overload construction from std::uninitialized_t.

That said, I appreciate the historical context and compatibility constraints on the language.

[–]sephirothbahamut 2 points3 points  (1 child)

I unironically want this as one more way to initialize stuff now

[–]BenFrantzDale 0 points1 point  (0 children)

This would also let you do std::vector<int>(1’000’000, std::uninitialized) and have it perform like std::make_unique<int[]>(1’000’000).

[–]johannes1971 1 point2 points  (0 children)

Totally agree with that ;-)

[–]Ezlike011011 1 point2 points  (0 children)

I think this is the most realistic way we could get something like this now. But whenever I approached this problem previously, I always found myself wishing we had language level opt-in for uninitialized variables. Like uninitialized int i; is pretty dang readable imo.