I was looking into std::set code. I see insert signature as _Pairib insert(const value_type& _Val). Why is the input parameter passed by reference? I know that standardcContainers copy their elements into memory of the container. Does anybody know how this is achieved? Where do allocators enter the picture? Any small code/pseudocode which explains how the elements are stored/inserted would be appreciated. I am interested in understanding how the copy is done.
I was looking into std::set code. I see insert signature as _Pairib insert(const value_type&
Share
The allocator is a template parameter. Look at the definition here:
If you don’t specify allocator of your own, it will take the default allocator (which would probably be just a
new).You can use STL containors on classes with public copy constructors, destructors and assignment operators. See here:
So basically the copy is done by using the above public member functions that you implement in your classes.