Proposal for scoped const contracts
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 24 13:46:26 PDT 2008
"Jason House" wrote
> Steven Schveighoffer Wrote:
>
>> So, how do we specify this?
>
> I'm not a D 2.x user yet, but wouldn't it simply be the following?
>
> char[] strchr(return char[] source, const char[] pattern);
>
> Note that pattern can always be const by the very nature of the function.
> Only the source argument needs to be coupled with the return type. I
> think this compactly reduces the various const forms into a simple and
> easy to define function. Having the return type be naked kind of bugs me
> a bit, but it if I can get away with writing just one function like that,
> I'm all for it.
This works for simple functions like the one you gave.
But there are other places where this does not work. For example, the min
function would require 2 return parameters. If you wanted to return a
member of a class that was an input value. This is really important with
properties, because you are generally tagging the 'this' pointer for const
variance, and so you most likely will not be returning an instance of a
class from a member function, but rather a member.
-Steve
More information about the Digitalmars-d
mailing list