Im working with boost::icl::interval_map that works perfectly but i want this container to be stored in shared memory. Does boost provide support for storing boost::icl containers in shared memory
using namespace std;
using namespace boost::icl;
struct IFM {
std::string destinationGroup;
int priority;
IFM()
{
destinationGroup= "";
priority = 0;
}
IFM(const std::string& d, const int& p)
{
destinationGroup= d;
priority = p;
}
IFM& operator +=(const IFM& right)
{
destinationGroup+= right.destinationGroup;
priority += right.priority;
return *this;
}
bool operator <(const IFM& left) const {
if(priority < left.priority)
return true;
}
bool operator ==(const IFM& left) const {
return destinationGroup== left.destinationGroup
&& priority == left.priority;
}
};
typedef std::set<IFM> guests;
void boost_party()
{
interval_map<double, guests> party;
IFM i = {"123", 1};
IFM j = {"124", 1};
IFM k = {"126", 2,};
IFM l = {"128", 1};
IFM m = {"129", 1};
IFM n = {"130", 1};
guests ii;
ii.insert(i);
guests jj;
jj.insert(j);
guests kk;
kk.insert(k);
guests ll;
ll.insert(l);
guests mm;
mm.insert(m);
party.add(make_pair(interval<double>::closed(12345600000,12345699999), guests(ii)));
party.add(make_pair(interval<double>::closed(32100000000,32199999999), guests(jj)));
party.add(make_pair(interval<double>::closed(42000000000,42999999999), guests(ll)));
party.add(make_pair(interval<double>::closed(42101000000,42101099999), guests(kk)));
party.add(make_pair(interval<double>::closed(67000000000,67999999999), guests(mm)));
interval_map<double, guests>::const_iterator it;
it = party.find(42101035898);
if (it != party.end()) {
interval<double>::type when = it->first;
guests who = (*it++).second;
cout << who.size() << endl;
for (auto it2 : who) {
cout << when << ": " << it2.destinationGroup<< endl;
}
}
}
int main() {
boost_party();
return 0;
}
Gives me following output which is expected Now i m trying to put a simple map interval_map in shared memory first but my code never compiles
boost::interprocess::managed_shared_memory segment(
boost::interprocess::create_only, "MySharedMemory" //segment name
, 65536);
typedef int KeyType;
typedef int MappedType;
typedef pair<int,int> keyvalue;
typedef boost::interprocess::allocator<keyvalue, boost::interprocess::managed_shared_memory::segment_manager>
ShmemAllocator;
ShmemAllocator alloc_inst (segment.get_segment_manager());
typedef boost::icl::interval_map<int, int, boost::icl::partial_absorber, std::less, boost::icl::inplace_plus,boost::icl::inter_section, boost::icl::discrete_interval<int, std::less>, ShmemAllocator> MyMap;
Give following error
error: type/value mismatch at argument 8 in template parameter list for ‘template class Compare, template class Combine, template class Section, class Interval, template class Alloc> class boost::icl::interval_map’ typedef boost::icl::interval_map, ShmemAllocator> MyMap;
error: expected a class template, got ‘ShmemAllocator {aka boost::interprocess::allocator, boost::interprocess::segment_manager, boost::interprocess::iset_index> >}’
error: invalid type in declaration before ‘;’ token