I don't see why it wouldn't be legitimate.
According to this comment:
a = a->imbue(std::move(a), op, std::move(b));
it looks like what you want is a consume operation. That is, the function consumes its inputs (ownership is transferred into the function, and they're deleted upon exiting), which is just what happens.
One of the being-deleted objects happens to be the one you call the member function on, but although that looks like it might be tricky, it sure is OK because at the time of the calling, the object is still guaranteed to live.
You return an object (presumably move since it's an unique_ptr
again) which is reassigned to the original name. So instead of c = a->imbue(a, op, b)
it's a
= a->imbue(a, op, b)
.
That's OK, why would it not be. It's incidentially the same name like the one of an object that just got deleted, but so what. The object is valid, and there's nothing in your way of reassigning something different to a name. You reassign something different to a name when you write x = x + 1;
as well, and nobody would object to that.
Something you may definitively want to avoid is (obviously, but maybe not so obvious?) calling imbue
with the same Expression
object in both locations.