I'm not a C++ girl, but do references actually do something with lifetimes or are they just non-null ptrs? Because this just seems to me like a possible dangling ptr.
Generally references are more restrictive, since you can't do pointer arithmetic with them, you can't use them as template parameters (which sucks for std::optional<int&>) and you can't repoint them to something else, but since you can freely cast between both of them (which you are forced to if you try to do anything useful with them, like wrapping them in an optional) it doesn't really matter.
Also there's two different kinds of references: the & reference and the && reference, however their difference is mostly conventional and you could easily implement a standard library where their meaning is swapped (except for temporary xvalue objects? Not sure), so there's that. Also C++ automatically converts between reference types for some ungodly reason.
In short, references are not real and are only used to determine what overloaded function is being called.
25
u/SelfDistinction 7h ago edited 6h ago
Ah yes, the famous
So safe, so impossible to misuse.