dcb - 2024-04-18

Given this C++ code:

include <string></string>

include <vector></vector>

using namespace std;

void f( string a)
{
}

void g( vector < string > b)
{
}

then cppcheck says the same thing for both functions:

apr18b.cc:9:16: performance: Function parameter 'a' should be passed by const reference. [passedByValue]
void f( string a)
^
apr18b.cc:13:27: performance: Function parameter 'b' should be passed by const reference. [passedByValue]
void g( vector < string > b)

Since copying a vector of strings will always be more expensive than copying a single string,
it would be a great help if cppcheck said something different in the second code, so in
a code base of thousands of these messages, I can grep for the more important ones first,
instead of having to check every one.

This generalises to other containers like map, set & list.