Thread overview
clear works better than it ought to considered i never defined it
Jul 28, 2014
Vlad Levenfeld
Jul 28, 2014
Mike
Jul 28, 2014
Vlad Levenfeld
July 28, 2014
A weird thing happened:

I was building a dictionary struct which contains a custom array of values and a differently-typed custom array of keys. Both of them implicitly define "clear" by aliasing a backing array.

The dictionary type doesn't have clear, though. And it doesn't alias anything. Yet when I call clear on it, not only does it work, but it clears both of the private contained arrays. I can't find any free clear function in Phobos.

Not that I'm complaining, but... what's going on here?
July 28, 2014
On Monday, 28 July 2014 at 06:27:44 UTC, Vlad Levenfeld wrote:
> A weird thing happened:
>
> I was building a dictionary struct which contains a custom array of values and a differently-typed custom array of keys. Both of them implicitly define "clear" by aliasing a backing array.
>
> The dictionary type doesn't have clear, though. And it doesn't alias anything. Yet when I call clear on it, not only does it work, but it clears both of the private contained arrays. I can't find any free clear function in Phobos.
>
> Not that I'm complaining, but... what's going on here?

I'm not sure, but is your code calling the runtime `clear` method:  https://github.com/D-Programming-Language/druntime/blob/master/src/object.di#L519

It has been marked for deprecation in the upcoming 2.066 release.

Mike
July 28, 2014
Yep, just checked in the debugger. So, that's actually a bad thing, then. Good thing its being deprecated!