It cannot be const , because it grows inside the function and is not passed by reference, because there is probably no point in doing this for the caller.
Also, if it were a non-constant reference, it would be impossible to use a temporary one. For example, you cannot make tis:
std::vector<int> v{ 1, 2, 3, 4 }; auto distance = std::distance(v.begin(), v.end());
juanchopanza
source share