Is there a precedent for std :: unique_ptr <std :: array <T, N >>
I came across something like:
using arr_t=std::array<std::array<std::array<int,1000>,1000>,1000>;
std::unique_ptr<arr_t> u_ptr;
The unique pointer was obviously used to solve the stackoverflow problem. Is there a case to use the previous code, and not just use it std::vector? Is there a real use case for std::unique_ptr<std::array<T,N>>?
+4
1 answer
The code above generates one continuous buffer of a billion elements with access [], which allows you to get elements in the form of a three-dimensional 1000-sided cube.
, .
,
using u_ptr=std::vector<std::array<std::array<int,1000>,1000>>;
arr_t 1000 . 2 handle. , , - , . , unique_ptr , , .
; .push_back({}) .
, , , ; , , , , . vector, , , roll-your-own-span-span .
, private inheritance using, , unique_ptr.
+7