Apologies, the optimizer might have been a bad example. It appears that the constructors of most objects I am dealing with at the moment–for example, torch::data::Example<>–do appear to take Tensor arguments passed by value. In that case, of course, there shouldn’t be an issue.
I guess I’m still wrestling with the idea of a “local copy” of a Tensor, which appears not to have a copy constructor. The Tensor class itself does not inherit from anything, it just maintains an intrusive_ptr to a TensorImpl, so it doesn’t inherit any copy semantics from anything itself. (Again, the copy constructor appears to be set to ‘delete’.)
It does have a default move constructor, and I guess a ‘default’ move constructor means that a move is executed on each member, which means a move on the intrusive_ptr being held by it. But it appears that the move constructor on the intrusive_ptr nulls the source pointer, which means the source Tensor has no state any more.
Sorry, there is a certain amount of thinking out loud here, but I’m just trying to understand how Tensor objects work under the hood, so I can use them in a way that doesn’t blow up my code. If re-use isn’t safe, I may have to resort to the clone() method, which strikes me as inefficient. But the gaps in my understanding are still quite large, so I am keeping my mind open.
Thanks again.