Question: I've been working on an implementation of the n-bodies problem, and I have to make a struct (asteroid) and a vector which contains those structs.

My question is, if I create the vector like this:

```
vector<asteroid> b(n_asteroids + n_planets);

```

And then I fill it like this:

```
for (it = 0; it < n_asteroids + n_planets; ++it){
  b[it] = {arg1, arg2, arg3...}
}

```

Do I need to call **delete** for either the asteroid structs or the vector? Or will the destructor free them when my program ends main?

Thanks!

Answer: 
I don't think your "modifier object" was ever proposed (AFAIK). And it will never go into the standard. Why? Because we already have a way to get rid of the expensive copy, and that is return by value (plus compiler optimizations).

Before C++17, compilers were allowed to do basically almost the same thing. This optimization is known as (N)RVO, which optimizes away the copy when returning a (named) temporary from a function.

```
auto a = f(other_arguments);

```

Will not return a temporary, then copy it into `a`. The compiler will optimize the copy away entirely, it is not needed. In theory, you cannot assume that your compiler supports this, but the three major ones do (clang, gcc, MSVC) so no need to worry - I don't know about ICC and the others, so I can't say.

So, as there is no copy (or move) involved, there is no performance penalty of using return values instead of output parameters (most probably, if for some reason your compiler doesn't support it, you'll get a move most of the time). You should always use return parameters if possible, and only use output parameters or some other technique if you measure that you get significantly better performance otherwise.
*(Edited, based on comments)*

You are right you should avoid output parameters if possible, because the code using them is harder to read and to debug.

Since C++11 we have a feature called [move constructors (see reference)](http://en.cppreference.com/w/cpp/language/move_constructor). You can use `std::move` on all primitive and STL containers types. It is efficient (question: [Efficiency difference between copy and move constructor](https://stackoverflow.com/questions/41054853/efficiency-difference-between-copy-and-move-constructor)), because you don't actually copy the values of the variables. Only the pointers are swapped. For your own complex types, you can write your own move constructor.
On the other hand, the only thing you can do is to return a reference to a temporary, which is of undefined behavior, for example:

```
#include <iostream>

int &&add(int initial, int howMany) {
    return std::move(initial + howMany);
}

int main() {
    std::cout << add(5, 2) << std::endl;
    return 0;
}

```

Its output *could* be:
 7

You could avoid the problem of temporary variables using global or static ones, but it is bad either. @Rakete is right, there is no good way of achieving it.