I’d like to write a function with a prototype like the following
void fun(Thing *one, Thing *two, Thing *ret);
I’d like to consider the fact that ret may or may not be aliased by one or two. This should be determined at runtime if needed, and the appropriate code called.
Is this a bad idea? Are there language semantics to have this?
EDIT: I haven’t made clear that I don’t want to test by hand like if (one == ret || two == ret) which naturally works but seems very verbose to me. Also, I don’t want duplicated code for two almost identical cases (only the qualifier differs). I am more looking for what is idiomatically a good solution, and if there are any language semantics supporting such cases.
A lot depends on the semantics of the classes in question, but it’s extremely rare to need a test for aliasing. Just obtain all of the information you need from
oneandtwobefore you start modifying anything. You might also want to ensure that you’ve finished anything which might raise an exception before starting modifications as well.