4 ms·
The Cpp Core Guidelines suggest that the cutoff between copy and const reference should be "up to two or three words" (item F.16). Following this advice, the f3
by nemetroid 7y ago
The Cpp Core Guidelines suggest that the cutoff between copy and const reference should be "up to two or three words" (item F.16). Following this advice, the f32 vector would be passed by value, and the f64 vector would end up in the grey zone.
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#f16-for-in-parameters-pass-cheaply-copied-types-by-value-and-others-by-reference-to-const https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...
- stochastic_monk 7y agoThat explains why I usually see std::span passed by value.
- bt848 7y agoSpans with extent known to the compiler are not even two words long. Like unique_ptr with default deleter they are the size of a pointer.
- mratsim 7y agoThat's what the Nim compiler does. Bigger than 3 words, pass-by-ref, otherwise pass-by-value. So the only important modifier is whether the parameter is mutable or not. Obviously if mutable it's always passed-by-reference.