I have the following case:
T* get_somthing(){
std::vector vec; //T is trivally-copyable
//fill vec
T* temp = new T[vec.size()];
memc
Isn't the way to go here simply to allocate the vector dynamically? That's how resources with a life time which is unrelated to scope are traditionally managed, and I don't see any reason to invent something extraordinary.
Of course that vector should be destroyed some time later; that may make it necessary to store its address somewhere as a side effect of get_somthing()
, but even then this strategy seems cleaner than any of the other ideas.