Equivalent of Python's dict.update for STL maps in C++
You're not thinking laterally here.  If you std::swap() your two inputs, then you can merge() the original into the new, and the contents of the new map will prevail.

Here's what I mean:

namespace codereview
{
    template &lt;typename DictT&gt;
    void update(DictT&amp; dst, DictT src)
    {
        std::swap(dst, src);
        dst.merge(src);
    }

}  // namespace codereview




// Test
#include &lt;iostream&gt;
#include &lt;map&gt;

template&lt;typename Map&gt;
void print(const Map&amp; x)
{
    for (auto const&amp; i: x)
        std::cout &lt;&lt; i.first &lt;&lt; "=" &lt;&lt; i.second &lt;&lt; " ";
    std::cout &lt;&lt; std::endl;
}

int main()
{
    using Map = std::map&lt;int, const char*&gt;;
    Map a { {0, "zero"}, {1, "one"} };
    const Map b { {0, "nothing"}, {2, "two"}};

    print(a);

    // test lvalue argument
    codereview::update(a, b);
    print(a);

    // test rvalue argument
    codereview::update(a, Map{{3, "three"}, {0, "nada"}});
    print(a);
}


Output

0=zero 1=one 
0=nothing 1=one 2=two 
0=nada 1=one 2=two 3=three 


Note that I changed the method signature to accept src by copy - the compiler will move-construct into src if it can, but if not, we'll need a copy so that we don't perturb the caller's version when we swap.