|
|
|
|
|
by melodyogonna
399 days ago
|
|
> What happens if you pass the variable mutably to a function? What happens in what manner? Mojo uses ASAP memory model, values will always be destroyed at the point of its last use. Mojo dataflow analysis will track this. In terms of safety, Mojo will enforce `alias xor mutability` - like in Rust. > C++ on the other hand has a copy constructor, and you have to move explicitly, often generating unnecessary copies (in the sense of clone) Mojo also has copy and move constructors, but unlike in C++ these are not synthesised by default; the type creator has to either explicitly define the constructors or add a synthesiser. In Mojo, you can have types that are not copyable and not movable, these types can only be passed by reference. You can also have types that are copyable but not movable, or movable but not copyable. |
|