Remix.run Logo
wtetzner 2 days ago

> members of a const struct are also const.

Yes, but if your struct contains references, the constness doesn't apply to what those references point to. In Rust it does.

mgaunard 2 days ago | parent [-]

For pointers, const only affects whether you can re-set it to point to something else, not the pointee.

Nothing prevents you from building a smart pointer with those semantics though, std::indirect is an example of this (arguably closer to Rust's Box).

wtetzner 2 days ago | parent [-]

Sure, but my point is that the semantics between C++ and Rust are different, and are therefore not an exact match as the article stated.

mgaunard 2 days ago | parent [-]

In C++, you define the semantics yourself.

wtetzner a day ago | parent [-]

No, const semantics are defined by the language definition.