samedi 25 décembre 2021

Why Sutter suggests store only values and smart pointers in containers?

I'm reading Herb Sutter's C++ Coding Standards item 79:

Store objects of value in containers: Containers assume they contain value-like types, including value types (held directly), smart pointers, and iterators.

I'm afraid that I didn't get the idea of why.

Question 1: when Sutter says contain, does he mean own? like "Containers assume they own value-like types"?

Question 2: besides value types, smart pointers, and iterators, what else types can be stored? for example, reference? Why reference is not recommended to be stored in containers?

Thanks

Aucun commentaire:

Enregistrer un commentaire