Boost logo

Boost :

From: Rainer Deyke (rdeyke_at_[hidden])
Date: 2021-03-24 14:05:17


On 24.03.21 14:46, Edward Diener via Boost wrote:
> Why are consts ignored in function parameters ? Is not
> void f(int const) different from void f(int) ? In one the argument
> passed can not be changed and in the other it can. How can they be the
> same ?

That's an implementation detail of the function f that doesn't (and
shouldn't) affect the interface, and the type of f is part of its interface.

Let's say that I write a function like this:

void countdown(int start_val) {
   while (start_val >= 0) {
     std::cout << start_val << "\n" << std::flush;
     --start_val;
   }
}

Later I realize that changing the value of the start_val parameter is
confusing, so I rewrite the function like this:

void countdown(int const start_val) {
   for (int val = start_val; val >= 0; --val) {
     std::cout << val << "\n" << std::flush;
   }
}

I am (and should be) allowed to make this change without affecting any
users of my function because it is purely an implementation change.

-- 
Rainer Deyke (rainerd_at_[hidden])

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk