The Phobos Put

ag0aep6g anonymous at example.com
Wed Mar 29 19:21:52 UTC 2023


On Wednesday, 29 March 2023 at 16:44:31 UTC, Ali Çehreli wrote:
> On 3/29/23 09:27, Salih Dincer wrote:
>
> > In this way,
> > it could also be used directly with slices. For example:
>
> > auto put(R)(R[] range, R[] source)
> >    => putImpl(range, source);
>
> That's for rvalues.
>
> > auto put(R)(ref R[] range, R[] source)
> >    => putImpl(range, source);
>
> That's for lvalues.
>
> If you are proposing keeping the current ref-taking Phobos 
> put() as well, then the following call would be ambiguous:
>
>   slice.put([2]);  // Compilation ERROR

As far as I understand, you're saying that we cannot overload on 
`ref`. But we can. Salih's code demonstrates just that.

void f(ref int x) {}
void f(int x) {}
void main() { int x; f(x); f(42); } /* no errors */


More information about the Digitalmars-d-learn mailing list