4 ms·
As many as mentioned before, i think the authors is mixing a lot of concepts and might be trying to write rust in C++ ( or vice-versa). From what i understand
by soulbadguy 3y ago
As many as mentioned before, i think the authors is mixing a lot of concepts and might be trying to write rust in C++ ( or vice-versa).
From what i understand the key here is that authors seem to be mixing references and pointers.
What the author wants here (std::box) is a garbage collected/RAII'ed reference to a heap allocated object.
smart_pointers are pointers... which is to say their identity is distinct from pointed object.
I don't think std::box is missing as much as it doesn't really fit well in C++ current memory model, and distinction between references, pointer and ownership.
- oasisaimlessly 3y agoC++ has lots of so-called "value types" and this would just be another. box<T> is basically a vector<T> that is constrained to always have a size of 1. Both internally store a pointer to the heap and implement value semantics for the pointed-to object(s).
- soulbadguy 3y agoAnd yet nobody use calls a vector of 1 a pointer. The question is not about the utility of box<T>, i am sure there are cases where such a structure would be need. But box<T> is not a "pointer" in the C++ sense same as an array/vector of 1 is not a pointer. The authors is needlessly complicating things and mixing concept there are pretty orthogonal. And i think this is the result of trying to fit box<T> which is not a pointer inside a taxonomy of pointers...