I came from a C++ world, so I'm used to passing structs by a
const reference (I mean the case, where a function argument isn't
changed by the function). C++ allows passing a temporary (rvalue)
to a function, which accepts a const reference. D doesn't allow
this. All I have found is a message from Andrei:
http://digitalmars.com/d/archives/digitalmars/D/const_ref_rvalues_103509.html#N103514 Sadly, he didn't describe the details there. Let's suppose he's right.
How should I pass a struct variable in D effectively? When
passing by a const reference, I need to implement 2^N additional
overloads, where N is the number of arguments. On the other hand,
passing by value can be very ineffective.
Maybe I shouldn't bother at all and a compiler is smart enough to
always optimize variables passed by value?
Please, share your best practices. There are many options here
(immutable, const, ref, in, out, inout) and I don't know what I
should prefer.
- Passing structs to functions phant0m via Digitalmars-d-learn
- Re: Passing structs to functions ketmar via Digitalmars-d-learn
- Re: Passing structs to functio... phant0m via Digitalmars-d-learn
- Re: Passing structs to fun... H. S. Teoh via Digitalmars-d-learn
- Re: Passing structs to fun... ketmar via Digitalmars-d-learn
- Re: Passing structs to... phant0m via Digitalmars-d-learn
- Re: Passing struc... Namespace via Digitalmars-d-learn
- Re: Passing s... ketmar via Digitalmars-d-learn
- Re: Passi... Namespace via Digitalmars-d-learn
- Re: Passi... ketmar via Digitalmars-d-learn
- Re: Passi... Namespace via Digitalmars-d-learn