SharedPtr.make

Constructs an object of type ElementType and wraps it in a SharedPtr using args as the parameter list for the constructor of ElementType.

The object is constructed as if by the expression emplace!ElementType(_payload, forward!args), where _payload is an internal pointer to storage suitable to hold an object of type ElementType. The storage is typically larger than ElementType.sizeof in order to use one allocation for both the control block and the ElementType object.

  1. auto make(Args args)
    struct SharedPtr
    static
    make
    (
    AllocatorType = DefaultAllocator
    bool supportGC = platformSupportGC
    Args...
    )
    (
    auto ref Args args
    )
    if (
    !isDynamicArray!ElementType
    )
  2. auto make(ElementReferenceType element, DeleterType deleter)
  3. auto make(size_t n, Args args)

Examples

{
	SharedPtr!long a = SharedPtr!long.make();
	assert(a.get == 0);

	SharedPtr!(const long) b = SharedPtr!long.make(2);
	assert(b.get == 2);
}

{
	static struct Struct{
		int i = 7;

		this(int i)pure nothrow @safe @nogc{
			this.i = i;
		}
	}

	SharedPtr!Struct s1 = SharedPtr!Struct.make();
	assert(s1.get.i == 7);

	SharedPtr!Struct s2 = SharedPtr!Struct.make(123);
	assert(s2.get.i == 123);
}

{
	static interface Interface{
	}
	static class Class : Interface{
		int i;

		this(int i)pure nothrow @safe @nogc{
			this.i = i;
		}
	}

	SharedPtr!Interface x = SharedPtr!Class.make(3);
	//assert(x.dynTo!Class.get.i == 3);
}

Meta