trusted purity?

monarch_dodra monarchdodra at gmail.com
Mon Apr 29 04:32:31 PDT 2013


On Monday, 29 April 2013 at 11:15:20 UTC, Henning Pohl wrote:
> I've been working on a pull request and came up with something 
> like this:
>
> private void initialize(A...)(auto ref A args)
> {
>     auto m = cast(void* function(size_t size) pure)&malloc;
>     _store = cast(Impl*) enforce(m(Impl.sizeof));
>     auto r = cast(void function(in void* p, size_t sz) nothrow 
> pure)&GC.addRange;
>     static if (hasIndirections!T)
>         r(&_store._payload, T.sizeof);
>     emplace(&_store._payload, args);
>     _store._count = 1;
> }

I always forget you can cast the type of a function...

> The purity of "emplace" depends on the purity of the ctor 
> called. I'm not sure how to fix that.

I'm not sure there's anything to fix there: If the CTor is not 
pure, then how could emplace be pure?

I did some work on emplace that is awaiting to be pulled, which 
should improve its purity.

On Monday, 29 April 2013 at 11:19:33 UTC, Henning Pohl wrote:
> By the way, my post is related to the impurity of RefCounted: 
> http://d.puremagic.com/issues/show_bug.cgi?id=9998

Yes, that is also what I am investigating. The cast is would 
indeed be a fix for malloc/free. RefCounted's 
isInitialized/refCount still need to be marked as pure though.

I'm still worried about what it means for a pure function to 
throw... (I'm thinking about the  "enforce(malloc)" scheme)


More information about the Digitalmars-d mailing list