> Container in C++ usually means something differently than what you use it here
I agree, that's my mistake. I did not mean it as a container in the classical sense. It's really a kind of smart pointer. I'm going to refer to it as such from now on.
> You can have that type today with wrapping unique_ptr and removing some methods, like release.
Of course. However if you have to both add and remove functionality, those are grounds to make it a separate object.
As this is an even more strict unique_ptr, I would like to see it implemented in the standard.
I believe more frequent usage of this could lead to safer code.
> How exactly this would not lead to an invalid state of box?
That is a fair point and something i had overlooked. This may have to be changed to something similar to emplace, where a value is placed
in instead or this is available only on default-constructible items, so a default value is placed inside.
> Swap is not semantics of any move constructor in standard library.
This does seem unconventional, yes, however, it does not seem to break the standard as "
Unless otherwise specified, all standard library objects that have been moved from are placed in a "valid but unspecified state", meaning the object's class invariants hold (so functions without preconditions, such as the assignment operator, can be safely used on the object after it was moved from)" (taken from cppreference.com)
> This just looks like bad design.
I agree, this isn't the cleanest thing. But for the purposes for this proposal, I mentioned this to increase cohesion with the rest of the standard library. You probably wouldn't use the box in cases where the C function has a chance to leave the pointer empty. This case does seem a bit niche, I can believe that.