Rust vector iteration less than 1 minute read The following example shows difference of iterating vector items between for and with iter() method 1 2 3 4 let vs = vec![1, 2, 3]; for (v : vs) { // consumes v, owned v } 1 2 3 4 let vs = vec![1, 2, 3]; for (v : &vs) { // borrows vs, & v } 1 2 3 4 let vs = vec![1, 2, 3]; for (v : vs.iter()) { // this is equivalent to for (v: &vs) } 1 2 3 4 let vs = vec![1, 2, 3]; for (v : vs.into_iter()) { // this is equivalent to for (v: vs) } Share on Twitter Facebook LinkedIn Previous Next
C++ - variadic template with fold expression less than 1 minute read C++ variadic template fold expression
C++ - lvalue, rvalue abbreviations less than 1 minute read lvalue: locatable value(addressable value) xvalue: expiring value glvalue: generalizable lvalue, it will be lvalue or xvalue rvalue: not addressable value(no...
C++ - unique_ptr for custom resource less than 1 minute read Using unique_ptr for a custom resource such as opening a file.