educative.io

Educative

Why key object is copyable and movable?

A user asked the following question

Can you explain why key object is copyable and movable ?

The author replied this:

Hello,

Let me answer the question more general. The containers of the STL have copy-semantic. This means, they want to own their elements. Consequentially, they have to copy their elements. When an element is copy-constructible, it is implicitly move-constructible beause copy kicks-in as fallback for move.

Rainer