As much as I enjoy C++ programming, there is one thing I really don't get. To me, it seems that the most common way of programming a function is like this:
some_function(a variable)
do something according to the data in the variable
example:
bool match_name(const std::string& name)
{
return this->name == name;
}
I find myself using const ref for 90% of all function parameters in my code (maybe I'm doing something wrong).
My question is: Why is a copy of the variable the "default" type of parameters? Why are not const ref the default?
Why not something like?:
void my_function(My_type object) // <- const ref
void my_function(ref My_type object) // <- ref (mutable)
void my_function(copy My_type object) // <- copy