This is a question about the interaction of stack memory and heap memory and the specific case of transition from stack to heap through std::arrayand classes std::vector.
In principle, std::array<T>it can be considered as a pointer to the first elements, as well as some compilation time information about the size of the array. Is it possible to have a constructor std::vector<T>that takes this fact into account and tries to move the contents arrayto vectorby simply copying the pointer.
A use case would be that it has a function that returns std::array<double, >
std::array<double, 20> fun(){...};
but later it is decided to assign it std::vectorwithout having to copy an element by element.
std::vector<double> v = fun(); // not working code
Now need to do
std::array<double, 20> tmp = fun();
std::vector<double> v(tmp.begin(), tmp.end());
, , std::vector<double> v(std::move(tmp)); \\ not working code.
std::vector std::array , .
, , std::array , std::vector . , std::vector, .
, , :
( ), ?
std::vector std::array?
MWE:
#include<array>
#include<vector>
std::array<double, 20> fun(){return {};}
int main(){
std::array<double, 20> arr = fun();
std::vector<double> v(arr.begin(), arr.end());
std::vector<double> v2 = fun();
}