Inout unclearness
Max Klimov via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 20 17:07:10 PDT 2015
On Monday, 13 July 2015 at 13:50:02 UTC, Steven Schveighoffer
wrote:
> With inout, it's even more tricky, because the compiler has to
> ensure it's not inout when it leaves the function. And it's not
> possible in some cases to do this.
> You can simply use a template function without hand-written
> cases. This is what inout was meant to replace.
Sure, however, it is still not the same as using inout.
Firstly, your function should be instantiated somewhere for
mutable T, const T and immutable T. Otherwise, compilation errors
will be postponed until the code usage.
Secondly, template function can not be virtual.
I'm wondering why it is needed to have special casting rules and
other restrictions for inout if people should treat inout as
wildcard for mutable, immutable and const. As far as I can
imagine, a compiler should generate one single object code for
inout function. Is it possible just to check validity of an
inout(T) function for T, const(T) and immutable(T) and then, if
success, generate the code? (keeping in mind that you can execute
another inout functions inside this one). Am I missing something?
-Max
More information about the Digitalmars-d
mailing list