On Friday, 20 May 2016 at 20:45:05 UTC, Jonathan M Davis wrote:
If you want something that's ref-counted and works in pure code, const will _not_ work, because you can't legally alter the ref-count.

What about something like this (ignoring multi-threading issues):

struct RefCountPool {
   size_t acquireIndex();
   void releaseIndex(size_t index);

   size_t* accessRefCounter(size_t index);
}

RefCountPool refCountPool;

struct SharedPtr
{
   size_t index;
   void* ptr;

   SharedPtr(void* ptr) {
       this.ptr = ptr;
       index = refCountPool.acquireIndex();
   }

   // more methods, counter manipulation through accessRefCounter
}

Is is still legal? Would it breach @pure requirements (I believe so...)? After all it doesn't differs much from having a pointer instead of index.

Reply via email to