SharedPtr.alloc

Constructs a SharedPtr with element as the pointer to the managed object using allocator with state.

Uses the specified deleter as the deleter. The expression deleter(element) must be well formed, have well-defined behavior and not throw any exceptions. The construction of deleter and of the stored deleter from d must not throw exceptions.

  1. auto alloc(AllocatorType a, Args args)
  2. auto alloc(AllocatorType allocator, ElementReferenceType element, DeleterType deleter)
    struct SharedPtr
    static
    alloc
    (
    bool supportGC = platformSupportGC
    AllocatorType
    DeleterType
    )
    (
    AllocatorType allocator
    ,,
    DeleterType deleter
    )
    if (
    isCallable!DeleterType
    )
  3. auto alloc(AllocatorType a, size_t n, Args args)

Examples

auto a = allocatorObject(Mallocator.instance);

long deleted = -1;
auto x = SharedPtr!long.make(new long(123), (long* data){
	deleted = *data;
}, a);
assert(deleted == -1);
assert(*x == 123);

x = null;
assert(deleted == 123);

Meta