You can do it, but it's a little complicated.
My main concern is here if your motive. I understand that you do not want to pass large objects by value, but regardless of whether the large or large object is inconsequential - what you really want to know is how long it will take the copy constructor to create the parameter .
As a concrete example, the size of std::vector is actually very tiny, since it allocates all the memory on the heap and only a pointer is needed. However, copying a vector takes much longer. Something like this is not something you can really include in a state.
Your best bet here is just to pass by const & so that you cover the worst case. In addition, I cannot guarantee this, but I believe that the compiler would be smart enough to go by value if it thought it was more efficient.
Peter Alexander
source share