Basically he is saying there not to put raw pointers in containers and not to use the old auto_ptr
which as of C++17 has been removed from the standard library.
On your questions:
Question 1: when Sutter says "contain", does he mean "own"? like
"Containers assume they own value-like types"?
Actual value types -- like int
say -- do not have owners. Nothing owns 5 or 42. By "value-like" types he means types that are not exactly values but that have well-defined copying semantics so that you can pass them around as though they are values. std::shared_ptr
for example is like this. It is not a value but you can pass it around like a value. Sutter does not mention move-only types here because the book predates their existence in standard C++.
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?
Well, now you can store move-only types in containers e.g. std::unique_ptr. you just have to honor their move semantics.
You can't store naked references in containers. The STL containers are written generically and basically storing references in them doesn't work because copying a reference does not mean what the container implementations expect it to mean, i.e. double references are not part of C++. If you want to store references in STL containers you can use std::reference_wrapper.