It's a good habit to declare unchanging arguments as const
both to advertise in the function signature that you will not change them, and to allow the compiler to optimize around that parameter.
Any function with a non-const
argument implies it can or will modify that value, which if not true, communicates your intentions incorrectly.
Adding const
to everything might seem like a useless ritual, but it has a very important function.
As a note, it's usually not necessary to cast to a const
version of same. The compiler does that for you automatically. const
acts as a safety that's implicitly applied, but won't be removed without going out of your way to break it off.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…