The reason not to have const
on function arguments that are primitives is that it’s not part of the API. This is because C++ is pass by value. So no need to signal the user their value won’t be changed—it can’t be changed.
And no need to signal it internally, because C++ can cast away constness, so it can’t be enforced anyway.
If you look at the C++ standard library or Boost, you’ll see that none of the primitive arguments are marked const
anywhere.
Note that this is different than const double&
— that’s a reference and there const
signals something to the user.
- Bob
P.S. Could someone explain the difference between a “Topic” and a “Category” on Discourse?
and what writing to mc_stan+stan-dev@discoursemail.com does? I did this, but don’t know
if it’s the right thing to do for Discourse.