const debacle

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 21 10:12:57 PDT 2008


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 





More information about the Digitalmars-d mailing list