Proposal for scoped const contracts

Edward Diener eddielee_no_spam_here at tropicsoft.com
Mon Mar 24 15:34:38 PDT 2008


Steven Schveighoffer wrote:
> This idea has come from the discussion on the const debacle thread.
> 
> It is basically an idea for scoped const.  The main goal is so that one can 
> specify that a function does not modify an argument without affecting the 
> constness of the input.
> 
> The main problem to solve would be that I have a function with an argument 
> that returns a subset of the argument.  The easiest function to help explain 
> the problem is strchr.  Please please do NOT tell me that my design is 
> fundamentally unsound because you can return a range or pair, and then slice 
> the original arg based on that pair.  There are other examples that cannot 
> be solved this way, this is just the easiest to explain with.  Everyone who 
> uses C should know about strchr:
> 
> char *strchr(char const *source, char const *pattern);

In C++, assuming you meant strstr, this is:

char const * strstr(char const *source, char const * pattern);

I believe C++ has this right. I do not understand why D programmers want 
to return a non-const from a const input, even in the face of D slicing.



More information about the Digitalmars-d mailing list