How can I understand the below piece of Rust code with the corresponding C++ concept?
Below is my analysis regarding this snippet of code:
This is a reference to an array in Rust, but as we know, a reference in Rust is similar to a pointer in C++ which has top-level constness and bottom-level constness. But in C++, we cannot write it that way, meaning we cannot write a pure rvalue reference of an array. We can only write something like int &&x = 10
which indicates it is an rvalue-reference to a numeric value, namely a reference to a temporary value. If we use the pointer concept in C++ to imitate this Rust behavior, we cannot write a pointer directly pointed to a temporary value, right? So, how should I understand this?
fn main() {
let x = &[1, 2, 4];
}