Using pure to create immutable

Daniel Murphy yebblies at nospamgmail.com
Fri Sep 23 06:44:01 PDT 2011


"Jesse Phillips" <jessekphillips+D at gmail.com> wrote in message 
news:j5gfsa$2d5g$1 at digitalmars.com...
> Thank you this lets it compile. I think I had that somewhere, but forgot 
> about it. As Steve mentions, it probably should also work for const 
> arguments too.

It probably will, eventually.  Some expressions can be proven to be pure (in 
some situations), such as (new C), (arr ~ arr), (arr.dup) and 
(thisFunctionIsConstPure(args))

(doing this for arr ~ arr is the best solution to 
http://d.puremagic.com/issues/show_bug.cgi?id=1654, in my opinion)

As Steven pointed out, pure functions that have mutable return types cannot 
be opimized out, as the code could reasonably rely on returned objects being 
distinct.  Their return values can, however, be converted to immutable 
without any problems. 




More information about the Digitalmars-d-learn mailing list