Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-04-24 16:15:49


>From: "John Swartzentruber" <johnslists_at_[hidden]>

> On Thu, 24 Apr 2003 21:48:02 +0200, Terje Slettebø wrote:
>
> >You must of course do what you think is best in this situation. I just
hope
> >you got my point that if the calling code uses const, you don't have to
look
> >at the function signature, to determine what variables may or may not be
> >changed by a function.
>
> void func1(Classname& obj)
> {
> func2(obj);
> func3(obj);
> func4(obj);
> }
>
> You are maintaining someone's code and know that one of these functions
> is changing obj. How do you know which? I think I understand your point
> about the calling code using const, but in this case, where the object
> is non-const within the function because func1() changes the object,
> would you call const_cast for the functions that do not change the
> object?

I've been thinking of that, too, including that exact solution. Yes, it's a
possibility. It's quite messy, though. However, it's similar to the
proposal, that "something" is used at the calling side, to enforce/document
what may be changed or not.

> I think that would clearly document what is going on, but it
> seems unlikely that anyone does this when passing non-const references
> to functions that take a const references for their parameters. Do you
> do this?

No, I don't. In this case, it may not be easy to use constness. Here, other
things, which has been mentioned in this thread, such as good naming, etc.,
comes into play. Not to mention that it is in fact documented in the header.

Regards,

Terje


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