Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are move-aware containers? C++

Tags:

c++

c++11

What are move-aware containers in C++? I know std::vector is a move-aware container. But I don't know what move-aware means.

like image 409
miáo Avatar asked Oct 23 '25 10:10

miáo


1 Answers

The word move-aware container occurs in this context:

std::unique_ptr is commonly used to manage the lifetime of objects, including:
...
* as the element type in move-aware containers, such as std::vector, which hold pointers to dynamically-allocated objects (e.g. if polymorphic behavior is desired)

It means that the container knows how to handle move-only types. std::unique_ptr is a move-only type: it cannot be copied. This implies that a container holding objects of move-only types must itself be move-only.

like image 135
j6t Avatar answered Oct 26 '25 02:10

j6t