Thanks to Moritz and Stanislav for their examples, most useful. There are similarities (which I have just taken :-) but also some differences. Would one be considered more idiomatic D, or is it a question of different circumstances different approaches. The differences are mainly in construction I believe.
On Tue, 2017-05-30 at 00:31 +0000, Moritz Maxeiner via Digitalmars-d- learn wrote: > […] > > struct FrontendParameters_Ptr { > private: > dvb_v5_fe_parms* ptr; > public: > @disable this(this); > this(ref const FrontendId fei, const uint verbose = 0, const > uint legacy = 0) { ... } > ~this() { dvb_fe_close(ptr); } > auto c_ptr() const { return ptr; } > alias c_ptr this; > } > --- On Tue, 2017-05-30 at 00:32 +0000, Stanislav Blinov via Digitalmars-d- learn wrote: […] > > struct FrontendParametersPtr > { > // No constructors, initialization with parameters > // is done via the frontendParametersPtr function > @disable this(this); > > ~this() > { > // null check is often useful to detect e.g. > // if this object has been `move`d > if (_ptr) dvb_fe_close(_ptr); > } > > // with DIP1000, could also return `scope` > inout(dvb_v5_fe_parms)* ptr() inout { return _ptr; } > alias ptr this; > package: > > void construct(/*your args here*/) { /*...*/ } > > private: > dvb_v5_fe_parms* _ptr; > } > > /// Replaces constructor, i.e. can be called with no arguments for > /// replacing "default" construction of C++ > auto frontendParametersPtr(Args...)(auto ref Args args) > { > import std.functional : forward; > FrontendParametersPtr result = void; > result.construct(forward!args); > return result; // moves result, no copy is made > } > […] -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part