struct init property
Jonathan M Davis
jmdavisProg at gmx.com
Thu Aug 23 17:19:49 PDT 2012
On Friday, August 24, 2012 02:00:22 Namespace wrote:
> > I would expect you to be able to do
> >
> > test(NotNullable!Foo(new Foo));
> >
> > and with a helper function, you could have something like
> >
> > test(notNullable(new Foo));
> >
> > - Jonathan M Davis
>
> But then you have an lvalue and cannot receive it as "ref
> NotNullable!Foo". Your struct would be copied with the (default)
> postblit ctor every time you send it to "test", or am I wrong?
If you passed it a directly constructed NotNullable!Foo or the result of a
function, then it wouldn't be copied. It would be moved.
http://stackoverflow.com/questions/6884996/questions-about-postblit-and-move-
semantics
And even if it _were_ copied, we're talking about a struct that just holds a
class reference, so copying it would be essentially the same as copying the
reference. I wouldn't expect NotNullable to even _have_ a postblit
constructor, meaning that copying it would use memcpy, which would be very
fast. If you have to worry about the efficiency of passing NotNullable!T to a
function, then there's something very wrong.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list