phobos icon indicating copy to clipboard operation
phobos copied to clipboard

emplace doesn't warn about private constructors

Open jibal opened this issue 11 months ago • 2 comments

emplace could do a much better job of detecting the reasons for failure, but this seems like an obvious one (though the check isn't entirely trivial because you have to find the right ctor and check its visibility)

jibal avatar Dec 13 '24 08:12 jibal

I wouldn't worry too much. emplace will be deleted soon!

TurkeyMan avatar Dec 13 '24 09:12 TurkeyMan

In my emplace implementation [1], the way I handle this is by just calling the constructor without trying to check first whether it will succeed. If it works, great; if it doesn't, you get the error message straight from the compiler.

[1] https://github.com/pbackus/allocator-demo/blob/master/src/pbackus/lifetime.d

pbackus avatar Dec 26 '24 22:12 pbackus