basics

Quick Q:Why does std::set seem to force the use of a const_iterator?

Quick A: A set does not allow the modification of its keys.

Recently on SO:

Why does std::set seem to force the use of a const_iterator?

A set is like a map with no values, only keys. Since those keys are used for a tree that accelerates operations on the set, they cannot change. Thus all elements must be const to keep the constraints of the underlying tree from being broken.

Parameter or Argument?--Malte Langkabel

Did you know the difference?

Parameter or Argument?

by Malte Langkabel

From the article:

I often hear people getting confused when talking about parameters and arguments. That confusion grows even stronger when one of them knows the difference but the other one doesn’t. So let’s shed some light on this issue and spread the knowledge! Programming involves talking to each other but that doesn’t have to be more painful than it already is wink

Quick Q: How to express constness of a forwarding reference?

Quick A: To express constness, a const reference is what is needed.

Recently on SO:

How to express constness of a forwarding reference?

How can I express that f does not modify its parameter?

If the function doesn't modify its parameter then there is no benefit to using a forwarding reference. You use a forwarding reference when you want to forward the parameter on to some other function which cares whether the argument is an lvalue or an rvalue (because maybe there are separate overloads for lvalues and rvalues, and the rvalue one can be more efficient).

If your function doesn't modify the argument then it shouldn't need to care whether it has an lvalue or rvalue, so it can just take const T& unconditionally. That can bind to both lvalues and rvalues, and promises not to modify the parameter.

template<typename T>
void f(const T& t) { ... }