Is `alias this` a mistake?
IGotD-
nise at nise.com
Thu Aug 5 17:24:56 UTC 2021
On Thursday, 5 August 2021 at 16:46:53 UTC, H. S. Teoh wrote:
>
> In C++, this is worked around by requiring passing by reference
> instead by value. But in D, this kinda defeats the purpose of
> structs, the whole point of which is a by-value type that gets
> passed around as "glorified ints", as Andrei calls it. Once
> you need to pass things around by reference, structs lose their
> raison d'etre, and you might as well just use a class instead.
>
I never understood the benefit of structs are value types. In
what use case would you like to pass the value of a struct rather
than a reference. The struct will be copied on the stack which is
inefficient so in 99% of the cases you would like to use the
reference, especially when the parameter is const. If you need a
copy the called function could be responsible for that.
Could someone explain the benefit of this "glorified int".
More information about the Digitalmars-d
mailing list