On 02/03/2016 09:01 PM, Matt Elkins wrote:
[code] import std.algorithm; struct ResourceHandle(T, alias Deleter, T Default = T.init) { // Constructors/Destructor this(T handle) {m_handle = handle;} @disable this(this); ~this() {Deleter(m_handle);} // Operators @disable void opAssign(ref ResourceHandle lvalue); ref ResourceHandle opAssign(ResourceHandle rvalue) {swap(m_handle, rvalue.m_handle); return this;} // Methods @property inout(T) handle() inout {return m_handle;} @property T handle(T handle) {Deleter(m_handle); m_handle = handle; return m_handle;} T release() {T result = m_handle; m_handle = Default; return result;} private: T m_handle = Default; } [/code] This seems to cover most of my bases, but I still can't do things like this: [code] unittest { alias RH = ResourceHandle!(uint, (uint) {}); RH[] handles; handles ~= RH(5); // Compile error: ResourceHandle is not copyable because it is annotated with @disable } [/code]
Got it, thanks. That's a bug in the implementation, no two ways about it. No copy should occur there, neither theoretically nor practically. Please report it to bugzilla at http://issues.dlang.org. Thanks very much! -- Andrei