4 ms·
> "We'll instead take and return the vector directly" Won't this clone it?
by winrid 3y ago
> "We'll instead take and return the vector directly"
Won't this clone it?
- rbancroft 3y agoNot necessarily, although it's a bit complicated to understand in C++. Starting with C++17, there is a feature called guaranteed copy elision that works for many/most scenarios that you would want. You need to read through the following resources to understand it fully: https://en.cppreference.com/w/cpp/language/copy_elision https://en.cppreference.com/w/cpp/language/copy_elision https://en.cppreference.com/w/cpp/language/value_category https://en.cppreference.com/w/cpp/language/value_category
- spoiler 3y ago> Not necessarily, although it's a bit complicated to understand in C++. One could say this statement applies to most lines of C++ code. Lol
- winrid 3y agoIndeed :) Makes me appreciate the explicit copy() and ref semantics in Rust. Although I bet in most cases such a method gets inlined so it doesn't matter.
- masklinn 3y agoCopy elision exists, the author might just assume (or know) it'll trigger. The rules are way too arcane for me so I could not tell.