Hello all,
It seems that boost::interprocess::set won't compile if the key_type is pointer.
However, bip::vector or std::set works fine.
I'm using g++ 4.5.2 and boost 1.46.0 with linux 2.6.37.
Here is my code:
// compile command: g++ a.cpp -lboost_thread
namespace bip = boost::interprocess;
struct comp {
template<class Pointer>
bool operator()(Pointer a, Pointer b) const {
return *a < *b;
}
bool operator()(int a, int b) const {
return a < b;
}
};
typedef bip::managed_mapped_file::segment_manager segment_manager_t;
#define fset(value_t) \
bip::set >
bip::managed_mapped_file
managed_shm(bip::open_or_create, "/tmp/bip_test", 1024);
void bip_example()
{
fset(int*) s(comp(), managed_shm.get_segment_manager());
s.insert(new int (7)); ///< error: key_type can't be pointer in bip.
fset(int) s2(comp(), managed_shm.get_segment_manager());
s2.insert(int (7)); ///< ok: non-pointer is accepted.
std::set s3;
s3.insert(new int (7));
///< ok: int* works with STL, as well as shared_ptr, offset_ptr.
}
void more_example()
{
typedef bip::offset_ptr<int> optr;
fset(optr) s3(comp(), managed_shm.get_segment_manager());
bip::allocator
alloc_int = managed_shm.get_segment_manager();
optr p = alloc_int.allocate(1);
alloc_int.construct(p, 7);
s3.insert(p); ///< error: bip doesn't work with offset_ptr too.
typedef boost::shared_ptr<int> sptr;
fset(sptr) s4(comp(), managed_shm.get_segment_manager());
s4.insert(sptr(new int(7))); ///< ok: shared_ptr works fine.
}
Won't that fail to compile, or am I missing something?
Regards,
Tianjiao