I came up with the following table:
+-------------------------------------------------+-----------------------+-----------------+
| Should the callee be able to modify the object? | Is it a large object? | Semantics |
+-------------------------------------------------+-----------------------+-----------------+
| yes | yes | reference |
| yes | no | reference |
| no | yes | const reference |
| no | no | value |
+-------------------------------------------------+-----------------------+-----------------+
Now I am not really sure what a large
object is. Certainly everything bigger than a pointer, so 8 Bytes. But take a struct with one double
and you're already at 8 Bytes.
This answer talks about an overhead of making a reference. Since the question was asked more than 11 years ago, I didn't bother asking there for clarification. Maybe someone could go into detail if this is really a concern since creating a reference it certainly faster than creating a copy, no?
I am not asking when to use which semantics. I also know about
move
. Much more I am interested in:
Does my table make sense?,
Is size of the object really something to consider when deciding on what semantics to chose, since I think you should almost always use ref (AAR (made up and derived from AAA)) except for built-in's maybe? And
What is a
large
object? Anything larger than 8 Bytes?