Const not appropriate for primitive arguments in C++

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.

1 Like

I don’t know about the email, but regarding topic vs category: I think discourse uses “topic” to refer to individual threads, whereas “category” is for higher-level organization of topics.

Yes, Daniel verified that in person, too.

  • Bob