With the default copy constructor, any copy will be shallow and will not make a copy of the memory pointed to by data . Therefore, when you pass by reference, only two integers and a pointer will be transferred, for a total of approximately 12 bytes (depending on your architecture, i.e. the size of the pointer).
This difference is so small that it really doesn't matter whether you pass it by value or by reference. The latter can be a little faster, because the pointer can probably always be passed through the CPU register, and 12 bytes cannot, but this is really micro-optimization.
Personally, I pass anything other than primitive types to the default ( const ) link if I have no reason not to see it (see jupp0r answer ). The main advantage during development is that as the class grows, I donโt have to worry about when it gets too big and changes all my functions to follow the link.
As for the default iterators, C ++ by default: note that they are mainly for pointers. In fact, I know that to compile Microsoft Visual C ++ in release mode with optimizations turned on, iterators for adjacent data structures like std::vector will be reduced to this. I do not know if other compilers can do this, I would think so. However, you will notice that if you turn off optimization, then suddenly there is a difference between writing it++ and ++it in loops, for example, only because of the additional copy operation in the first case. Therefore, even a โcheap copyโ can make an impact if you do it often enough. As usual: when you are worried about performance, measure and decide based on numbers.
source share