Is OwnedArray still the best option for holding an array of Component’s or is there an STL class that will work just as well (or even better)?
A replacement is
std::vector<std::unique_ptr<Component>> myComponents;
but OwnedArray is one of the classes I hold on to, because it reads much nicer…
There are technical opinions which ones to choose out there for sure, I am looking forward to hear them…
2 Likes
That’s a nice idea - hadn’t thought of that.
I guess the appeal of OwnedArray is the simplicity of adding new items (myOwnedArray.add(new MyObjectClass())). Sadly the equivalent using std::vector::push_back with the same new syntax doesn’t work (you’d instead have to use std::make_unique?) so your code starts becoming a little less pretty.
I think I’ll stick with OwnedArray for now until someone can convince me of a technical reason not to…
I think std::vector<>::emplace_back should work for this…
Oh cool, I didn’t know about emplace_back - thanks!
