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 Want an efficient way to swap two pointers in C++. I wrote this code
#include<iostream>
#include<map>
#include<atomic>
#include<string>
using namespace std;
// MultiMap Object
struct mmap{
multimap<string,int> 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->stringTointmap.insert(make_pair("old",1));
//populate second object
new2->stringTointmap.insert(make_pair("new1",2));
//swap two objects
atomic<swapMap> swap;
auto refresh=swap.load();
refresh= {swap.m2,swap.m1};
}
But I'm getting this error
error: expected expression
refresh= {swap.m2,swap.m1};
definitely, I'm missing something, could someone please help?