Encapsulate arguments

alex burton alexibu.remove at me.com
Wed Jan 1 17:07:00 PST 2014


On Wednesday, 1 January 2014 at 23:11:49 UTC, Adam D. Ruppe wrote:
> On Wednesday, 1 January 2014 at 23:00:33 UTC, alex burton wrote:
>> In D this would be void bar(in Init init) which makes init 
>> const
>
> You should just take Init, without the in.
>
> "in" means that you won't modify AND that you won't let any 
> reference to the argument escape the function's scope. The 
> second part isn't enforced by the compiler right now, but this 
> may change at some point.
>
> "in" basically is "look, don't keep", and since ctor arguments 
> are often kept in the class, it isn't ideal there.
>
> But plain non-const, non-in structs should be fine, that works 
> the same way as a regular function argument list.

Thanks but won't the struct be copied at every function call then 
?


More information about the Digitalmars-d mailing list