Example #1
0
int set_test_copyable ()
{
   typedef typename MyBoostSet::value_type IntType;
   const int max = 100;

   BOOST_TRY{
      //Shared memory allocator must be always be initialized
      //since it has no default constructor
      MyBoostSet *boostset = new MyBoostSet;
      MyStdSet *stdset = new MyStdSet;
      MyBoostMultiSet *boostmultiset = new MyBoostMultiSet;
      MyStdMultiSet *stdmultiset = new MyStdMultiSet;

      for(int i = 0; i < max; ++i){
         IntType move_me(i);
         boostset->insert(boost::move(move_me));
         stdset->insert(i);
         IntType move_me2(i);
         boostmultiset->insert(boost::move(move_me2));
         stdmultiset->insert(i);
      }
      if(!CheckEqualContainers(boostset, stdset)) return 1;
      if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;

      {
         //Now, test copy constructor
         MyBoostSet boostsetcopy(*boostset);
         MyStdSet stdsetcopy(*stdset);

         if(!CheckEqualContainers(&boostsetcopy, &stdsetcopy))
            return 1;

         MyBoostMultiSet boostmsetcopy(*boostmultiset);
         MyStdMultiSet stdmsetcopy(*stdmultiset);

         if(!CheckEqualContainers(&boostmsetcopy, &stdmsetcopy))
            return 1;

         //And now assignment
         boostsetcopy  = *boostset;
         stdsetcopy  = *stdset;

         if(!CheckEqualContainers(&boostsetcopy, &stdsetcopy))
            return 1;

         boostmsetcopy = *boostmultiset;
         stdmsetcopy = *stdmultiset;
        
         if(!CheckEqualContainers(&boostmsetcopy, &stdmsetcopy))
            return 1;
      }
      delete boostset;
      delete boostmultiset;
   }
   BOOST_CATCH(...){
      BOOST_RETHROW;
   }
   BOOST_CATCH_END
   return 0;
}
Example #2
0
int set_test_copyable ()
{
   typedef typename MyShmSet::value_type IntType;
   const int memsize = 65536;
   const char *const shMemName = test::get_process_id_name();
   const int max = 100;

   try{
      //Create shared memory
      shared_memory_object::remove(shMemName);
      ManagedSharedMemory segment(create_only, shMemName, memsize);

      segment.reserve_named_objects(100);

      //Shared memory allocator must be always be initialized
      //since it has no default constructor
      MyShmSet *shmset =
         segment.template construct<MyShmSet>("MyShmSet")
            (std::less<IntType>(), segment.get_segment_manager());

      MyStdSet *stdset = new MyStdSet;

      MyShmMultiSet *shmmultiset =
         segment.template construct<MyShmMultiSet>("MyShmMultiSet")
            (std::less<IntType>(), segment.get_segment_manager());

      MyStdMultiSet *stdmultiset = new MyStdMultiSet;

      for(int i = 0; i < max; ++i){
         IntType move_me(i);
         shmset->insert(boost::move(move_me));
         stdset->insert(i);
         IntType move_me2(i);
         shmmultiset->insert(boost::move(move_me2));
         stdmultiset->insert(i);
      }
      if(!CheckEqualContainers(shmset, stdset)) return 1;
      if(!CheckEqualContainers(shmmultiset, stdmultiset)) return 1;

      {
         //Now, test copy constructor
         MyShmSet shmsetcopy(*shmset);
         MyStdSet stdsetcopy(*stdset);

         if(!CheckEqualContainers(&shmsetcopy, &stdsetcopy))
            return 1;

         MyShmMultiSet shmmsetcopy(*shmmultiset);
         MyStdMultiSet stdmsetcopy(*stdmultiset);

         if(!CheckEqualContainers(&shmmsetcopy, &stdmsetcopy))
            return 1;

         //And now assignment
         shmsetcopy  = *shmset;
         stdsetcopy  = *stdset;

         if(!CheckEqualContainers(&shmsetcopy, &stdsetcopy))
            return 1;

         shmmsetcopy = *shmmultiset;
         stdmsetcopy = *stdmultiset;

         if(!CheckEqualContainers(&shmmsetcopy, &stdmsetcopy))
            return 1;
      }
      segment.destroy_ptr(shmset);
      segment.destroy_ptr(shmmultiset);
      segment.shrink_to_fit_indexes();
      if(!segment.all_memory_deallocated())
         return 1;
   }
   catch(...){
      shared_memory_object::remove(shMemName);
      throw;
   }
   shared_memory_object::remove(shMemName);
   return 0;
}