I can create constexpr
std::array:
constexpr std::array<int,5> values {1,2,3,4,5};
It works fine. But I cannot create constexpr
vector:
constexpr std::vector<int> vec = {1,2,3,4,5};
It gives me an error:
the type 'const std::vector<int>' of constexpr variable 'vec' is not literal constexpr std::vector<int> vec = {1,2,3,4,5};
vector
constructor is not declaredconstexpr
. Why is it not so declared? Becausevector
constructor generally needs to allocate memory on the heap, which of course can only be done at run time. – Igor Tandetnikvector
is its ability to resize dynamically. If you don't need that, just usestd::array
or plain array. – Igor TandetnikQt
and there are nothing likestd::array
container, so I tried to useQVector
andQList
and it does not work. I don't want to mixQt
andstl
containers. So, I guess now I have to – Leo