(no title)
jklowden | 4 months ago
Pass by value describes the semantics of a function call, not implementation. Passing a const reference in C++ is pass-by-value. If the user opts to pass "a copy" instead, nothing requires the compiler to actually copy the data. The compiler is required only to supply the actual parameter as if it was copied.
mattnewport|4 months ago
The semantics of pass by const reference are also not exactly the same as pass by value in C++. The compiler can't in general assume a const reference doesn't alias other arguments or global variables and so has to be more conservative with certain optimizations than with pass by value.
duped|4 months ago
themafia|4 months ago
I can cast the const away. The implementation does not hide this detail. The semantics therefore must be understood by the programmer.
Ericson2314|4 months ago
kazinator|4 months ago