const debacle

BCS BCS at pathlink.com
Fri Mar 21 10:37:18 PDT 2008


Steven Schveighoffer wrote:
> This issue was just brought to my attention, and I wonder if the other 
> const-proponents have a good solution for this.  This is going to be very 
> tough to deal with.
> 
> How do you declare a function that takes an array, is not allowed to change 
> the array, but returns a slice into the argument array, and the return type 
> matches the argument type.
> 
> For example, if I pass a mutable array to this function, I want it to pass 
> me back a mutable slice into the array, but I also want a guarantee that the 
> function will not modify the array.  I can't declare the argument is const 
> because then the return value must also be const, as it is a slice of the 
> original array.
> 
> How does one solve this problem?
> 
> -Steve 
> 
> 

IIRC Walter has something planed for this. Something to do with a 
"return" const type. It would do just that; "the function's return type 
has the same constness as one of it's arguments."

In short: Not yet.



More information about the Digitalmars-d mailing list