const debacle
Janice Caron
caron800 at googlemail.com
Mon Mar 24 10:36:02 PDT 2008
On 24/03/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> No, it is not a solved problem. As a caller of a function, you still cannot
> rely on the compiler verifying that a function does not modify it's
> arguments for mutable arguments.
I don't follow that. I believe that at least two of the three
solutions do indeed make that guarantee.
Solution 2: Explicit cast
T strchr(T)(const T s, char c)
{
return cast(T)(whatever);
}
The declaration of s as "const T" guarantees that the function body
will not modify s.
Solution 3: Return a range
Range!(uint) strchr(const(char)[] s, char c)
The declaration of s as "const(char)[]" guarantees that the function
body will not modify the elements of s.
More information about the Digitalmars-d
mailing list