title: swap c++ map objects in multithreaded environment
body: <p>I am new to c++ coding and have a need to swap/replace the old multimap object with the newly built multimap object, as this object will be cache I would like to replace the existing object only after building the new object and just replace the object itself. This will be used in a multithreaded environment, so using the atomic load. As described in this thread <a href="https://stackoverflow.com/questions/29512112/want-an-efficient-way-to-swap-two-pointers-in-c][1]">Want an efficient way to swap two pointers in C++</a>. I wrote this code</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;map&gt;
  #include&lt;atomic&gt;
  #include&lt;string&gt;
  using namespace std;
  
  // MultiMap Object
  struct mmap{
  multimap&lt;string,int&gt; stringTointmap;
  };
  
  // Structure to swap two instances of multimap
  struct swapMap{
    mmap* m1;
    mmap* m2;
  };
  
  int main(){
  
  //create Two Objects
  mmap* old = new mmap();
  mmap* new2= new mmap();
  
  // populate first object
  old-&gt;stringTointmap.insert(make_pair("old",1));
  //populate second object
  new2-&gt;stringTointmap.insert(make_pair("new1",2));
  
  //swap two objects
  atomic&lt;swapMap&gt; swap;
  auto refresh=swap.load();
  refresh= {swap.m2,swap.m1};
  }
  </code></pre>
  
  <p>But I'm getting this error</p>
  
  <pre><code>error: expected expression
  refresh= {swap.m2,swap.m1};
  </code></pre>
  
  <p>definitely, I'm missing something, could someone please help?</p>