any news on const/invariant?

Dan murpsoft at hotmail.com
Mon Dec 17 16:06:25 PST 2007


Bruce Adams Wrote:
> const is about the interface contract for a function. There is no  
> difference
> between    const valueType1 foobar(const valueType1)
> and        valueType1 foobar(valueType2)
> 
> valueType1 is not an l-value and therefore not assignable etc.
> 
> valueType2 the situation is not quite the same but I would contend that..
> Whether or not valueType2 is modified by foobar is an implementation  
> detail and should
> not be part of the contract.
> You can just as easily say in the body:
> 
> foobar(valueType2 bar)
> {
>    const valueType2 IamConst = bar;
>    ... use IamConst
> }
> 
> or
> 
> foobar(const valueType2)
> {
>    valueType2 IamNotConst = bar;
>    ... use IamNotConst
> }
> 

What if I want to pass a struct by value without copying - because I only want the changed struct?  (the function is SUPPOSED to modify my struct?)

In fact, that's just about the only time I ever pass structs to functions - when I want to modify them, or when I want to get something out of them.  Rarely ever because I want to copy them and keep both the unmodified copy and the modified one.

Regards,
Dan



More information about the Digitalmars-d mailing list