Moving an element from one unordered_map to another This code moves one element from one unordered_map to another.

I would like to ask if my code below can be improved.

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;utility&gt;
#include &lt;unordered_map&gt;

int main()
{
    struct Data
    {
        int foo;
        bool boo;
    };
    std::unordered_map&lt;std::string, Data&gt; map_A = {{"A", {1, true}}, {"B", {2, false}}};
    std::unordered_map&lt;std::string, Data&gt; map_B = {{"C", {3, false}}, {"D", {4, true}}};;

    std::string keyToMove = "C";
    map_A.insert({keyToMove, map_B[keyToMove]});
    map_B.erase(keyToMove);

    std::cout &lt;&lt; "map_A" &lt;&lt; std::endl;
    auto it = map_A.begin();
    while(it != map_A.end())
    {
        std::cout&lt;&lt;it-&gt;first&lt;&lt;" :: "&lt;&lt;it-&gt;second.foo&lt;&lt;std::endl;
        it++;
    }
    std::cout &lt;&lt; "map_B" &lt;&lt; std::endl;
    auto it2 = map_B.begin();
    while(it2 != map_B.end())
    {
        std::cout&lt;&lt;it2-&gt;first&lt;&lt;" :: "&lt;&lt;it2-&gt;second.foo&lt;&lt;std::endl;
        it2++;
    }
    return 0;
}


Result:

map_A
C :: 3
B :: 2
A :: 1
map_B
D :: 4
Program ended with exit code: 0
Unused Includes
The code is not using std:vector, nor is it using anything from utilities. It might be better not to include these, that can improve your compile time and decrease the size of the generated code.

Don't Repeat Yourself
There are two obvious functions that can be written to shorten the code in main(). One function prints the contents of an unordered map and the other moves the contents from one map to the other. When you see code repeating itself in a function that is a good indication that you can create a function to reduce the amount of code in the function to make it simpler.

Program Exit Status
In this particular program it isn't necessary to have return 0; in main() C++ will generate it for you. When you have programs that might fail it might be better to include cstdlib and use the symbolic constants EXIT_SUCCESS and EXIT_FAILURE to indicate success or failure to the calling program.