this is because complex has a constexpr constructor.
Now what if we want to work with vectors at compile time? after all vector constructors are also marked with constexpr?
constexpr vector v{ 1,4,8,12,34,66 };
this does not compile because we have heap allocation! but then why are vector constructors marked constexpr??
You can use std::vector in constexpr contexts but there is, as far as I know, no way to construct a std::vector at compile time and make it survive until runtime.
But the big limitation is that whilst these are evaluated at compile time, their 'lifetime' ends with the end of compilation. You can't (at present) initialise dynamic memory at compile-time and have it available initialised at run-time. You can with std::array as that doesn't use dynamic memory (its just a wrapper around c-style arrays).
> no way to construct a std::vector at compile time and make it survive until runtime.
The standard does not allow it; it requires that allocation and deallocation must be 'within the evaluation of the constant expression' https://eel.is/c++draft/expr.const#5.18
This is fine:
1 2
// fine: allocation and deallocation are within the evaluation of the constant expression
constexpr std::size_t n = std::vector<int> { 0, 1, 2, 3, 4, 5, 6 }.size() ;