Array as an argument, ambiguous behaviour.
Cooler
kulkin at hotbox.ru
Thu Jan 30 01:56:43 PST 2014
On Thursday, 30 January 2014 at 09:26:56 UTC, Stanislav Blinov
wrote:
> On Thursday, 30 January 2014 at 09:14:43 UTC, Cooler wrote:
>
>> Please stop explain me how fun3() works. I know that.
>> One of the main idea of D is that things must work as planned,
>> or would not compile at all. First and second variants follow
>> this idea. But fun3() can work not as planned on the caller
>> side (depends on fun3() body's implementation).
>> The question again - may be prohibit fun3() variant? If we
>> prohibit it, what use cases we could not implement with fun1()
>> and fun2()?
>
> Goodness... You've been shown this use case like a zillion
> times already: the caller manages her buffer, fun3() is allowed
> to change contents, but not reallocate caller's buffer.
>
> fun1() can't provide that (const), fun2() cannot either,
> because it explicitly allows reallocation (ref). This behavior
> is only provided by fun3().
>
> So it's either that, or indeed cases of "I don't care about
> this array", which Maxim Fomin has mentioned.
May be I am dumb...
If "I don't care about this array", I can use any of fun1() or
fun2().
Can you formulate contract to fun3()? Something like "Change
content of an array, but if you need to change the size - don't
do it!" Do you think so?
More information about the Digitalmars-d-learn
mailing list