vendredi 12 mars 2021

Is it Undefined Behavior to write `return {data, uninitialized_copy(b, e, data)};` in C++

Hi i am reading an example of how to define our own vector like class without using templates from one of the books. Now here there is one function which is defined as follows:

pair<string *, string*> StrVec::alloc_n_copy(const string *b, const string *e)
{
   auto data = alloc.allocate(e - b);
   return {data, uninitialized_copy(b, e, data)};

}

Now my question is that is the above return statement undefined behavior? For example i know that the following below statement is undefined behavior:

std::cout<< i << ++i<<std::endl;

Since this example statement is undefined, shouldn't the return statement also be undefined?, since it also changes the value of the variable data.

Aucun commentaire:

Enregistrer un commentaire