function not callable using struct constructor
Namespace
rswhite4 at googlemail.com
Thu Jan 2 23:36:31 PST 2014
On Friday, 3 January 2014 at 03:13:13 UTC, alex burton wrote:
> struct Foo
> {
> };
>
> void bar(ref Foo f)
> {
> }
>
> void main()
> {
> bar(Foo()); //Error: function test.bar (ref Foo f) is not
> callable using argument types (Foo)
> }
>
> I get the above error with 2.064 not with 2.060.
> Is it a bug ?
>
> Is it a feature ?
> If so :
> Why can't I take a non const ref to a temp struct - It might
> look a bit silly but I might be doing it to avoid copying.
>
> I could still do this :
>
> void main()
> {
> Foo f = Foo();
> bar(f);
> }
>
> Which is equivalent AFAIK
dmd 2.060 created a temporary variable, if you pass an rvalue by
ref. This variable is then an lvalue and is passed by ref to the
functions. But all versions after dmd 2.060 do not. What you are
searching for is auto ref, but this only works with templates. I
had several discussions (and also a DIP) and you will find many
many more, that we need auto ref even for non templates. You will
hear from Jonathan, Walter and Andrei that it will come *some
day*.
What you have to do is to overload both: ref and none ref. The
compiler chooses the right functions for you, so you have no
copies.
More information about the Digitalmars-d
mailing list