On Mon, 12 Jan 2015 20:14:19 +0000
jmh530 via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> Thanks for the reply, I wasn't familiar with scoped. I was aware 
> that structs are on the stack and classes are on the heap in D, 
> but I didn't know it was possible to put a class on the stack. 
> Might be interesting to see how this is implemented.
actually, there is nothing complicated there (if you don't want to
write an universal thing like `emplace!` ;-). it builds a wrapper
struct big enough to hold class instance, copies class `.init` there
and calls class' constructor. the rest of the magic is done by the
compiler: when struct goes out of scope, compiler calls struct
destructor, which in turn calls class destructor. ah, and it forwards
all other requests with `alias this` trick.

> After looking up some more C++, I think what I was trying to do 
> is more like make_unique than unique_ptr.
i don't remember C++ well, but nevertheless i encouraging you to take a
look at `std.typecons`. there are some handy things there, like
`Rebindable!` or `Nullable!`. and some funny things like `BlackHole!`
and `WhiteHole!`. ;-)

it even has `RefCounted!`, but it doesn't play well with classes yet
(AFAIR).

Attachment: signature.asc
Description: PGP signature

Reply via email to