std::array or QVector
-
In pure C++ it is now considered good practice to declare a Container with always a fixed size as
std::array
. I wonder how is it with using the QT Framework. From what i know theres noQArray
So whats the solution here? UsingQVector
orstd::array
? -
Hi,
It depends on your use case and features you seek. Qt containers are COW by default so cheap to copy for example.
-
@SGaist said in std::array or QVector:
COW
Well im building a dungeon which is represented by 20 Rooms. In this case the dungeon is designed to only work with 20 Items because they get connected as a Dodekaeder.
My functions to connect the Rooms as Dodekaeder only work for therefore for 20 Rooms.
It would be nice to only allow containers to get passed to it with size of 20. If I would use
QVector
I have to atleast assert in the function that thesize
is correct. Withstd::array<Room *, 20>
it would be cleaner the intend that only 20 is allowed. -
@sandro4912 said in std::array or QVector:
In pure C++ it is now considered good practice to declare a Container with always a fixed size as std::array
Who says this? Reference? This is highly dependent upon use case. std::vector is not any slower if you code correctly (for non-trivial use cases).
-
Then use std::array since it suites your needs.