If there is function with the following signature:
std::vector<std::vector<std::string>> some_func();
And its assigned to a variable of the same type:
std::vector<std::vector<std::string>> var = some_func();
What would be the time complexity of this assignment operation. The obvious assumption is this will be a move assignment operation and will be faster than a regular element by element copy into var.
But I am not sure if the move assignment operation will only move the location/size information of the outer vector to var and let the pointers and size information of the inner vectors be the same, or would the inner vectors be also moved element by element?
If that is the case, would the rvalue referencing be faster? :
std::vector<std::vector<std::string>>&& var = some_func();
std::vector<T>moves the size and the internal pointer and that's all. It doesn't care about whatTis.some_funcis a prvalue, then a direct initialization happens at absolute zero cost. Rvalue reference usage needs extreme caution to avoid dangling in specific senarios. Unless the objective is not to get a jagged array, vector of vectors is not encouraged; for 2D arrays, a single flat vector and the row size need be kept. You canstd::views::chunkit on indexing/iteration.std::views::chunkconsidered better thanmdspannow?mdspan. I mean whats the catch? I can use a fold expression ofchunks to emulate themdspan. It allows to aquire adapters on individual dimensions. Allmdspanoffers is a fancy indexing operator([]); is it really anything more than syntactic suger? WithchunkI have all std algorithms at my disposal; what can I do withmdspan?mdspan, and it's a fair bit less ceremony, especially if you uselayout_left.chunkis more general in what it accepts, as it only needsinput_range, notcontiguous_range.