C++ needs those extra categories, they exist for good reasons. But it is more complex.
C++ needs those extra categories, they exist for good reasons. But it is more complex.
const HUGE: usize = 10_000_000;
let mut values = Box::<[i32]>::new_uninit_slice(HUGE);
for k in 0..HUGE {
values[k].write(42);
}
let values = values.assume_init();
Edited to fix early enter oops, typo in loop length that'd be caught if I'd tried this.IMO, it would be really nice if the naive syntax was guaranteed to work, rather than requiring programmers to remember a new workaround syntax (new_uninit_slice() was only stabilised a year ago). This edge case is a little annoying because the naive approach will usually work for a release build, but then fail when you with back to a debug build.
I am sympathetic to desire to make it "just work" in proportion to how much I actually see this in the wild. Large heap allocations, initialized in place in a single sweeping action. It does happen, but I don't reach for it often.
Often people say "Oh, well I will finish initializing it later but..." and now we're definitely talking about MaybeUninit 'cos if you've only half finished the Goose, that's not a Goose yet, that's a MaybeUninit<Goose> and it's crucial that we remember this or we're writing nonsense and may blow our feet off with a seemingly harmless mistake elsewhere.
But yes, I used C++ extensively about 20 years ago and no longer understand any new developments in this language.
Writingefficient linked lists in rust OTOH requires more advanced concepts.
But that's because the language gives you more guarantees about safety than C++. That safety is not only important for the implementation of your code but also for the memory safety of your code when combined with other code that calls your code
There’s some weird examples here involving functions, function pointers, template parameters, and a few other things.
Do you mean assignment?