[Issue 5081] Pure functions as initializers for immutable structures

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 24 12:50:36 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5081



--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-02-24 12:47:49 PST ---
(In reply to comment #0)

> Michel Fortin also noticed a nice-to-have: if at the call site you know that
> all the arguments you're feeding the function with are immutable, then you can
> automatically cast the result to immutable, even if the function can also
> accept const arguments.

Note actually that as long as you can verify the return value did not come
directly from the parameters, it's also possible to implicitly cast to
immutable.

For example:

pure T[] mydup(T)(const(T)[] param) {...}

It's provable that the return value did not come from param (without a cast),
because you can't implicitly cast param to T[].  So you can cast the result to
immutable, even if param began as mutable.

This might be really tricky to implement though, there can be all sorts of
weird cases.

But if this could be accomplished, it would completely negate the need for
idup.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list