1 | #include <boost/move/unique_ptr.hpp>
|
---|
2 | #include <boost/interprocess/offset_ptr.hpp>
|
---|
3 | #include <boost/intrusive/pointer_traits.hpp>
|
---|
4 |
|
---|
5 | using boost::interprocess::offset_ptr;
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Note: this example does not necessarily need to make
|
---|
9 | * much sense. It is meant only to show the problem,
|
---|
10 | * the reasons why this is needed would be a bit
|
---|
11 | * long to explain, but they have to do with virtuality
|
---|
12 | * being forbidden in shared memory.
|
---|
13 | */
|
---|
14 |
|
---|
15 | struct B {};
|
---|
16 | struct D : public B {};
|
---|
17 |
|
---|
18 |
|
---|
19 | struct Deleter
|
---|
20 | {
|
---|
21 | typedef offset_ptr<B> pointer; // e.g. requirement of boost::interprocess::shared_ptr
|
---|
22 | void operator() (offset_ptr<void> p)
|
---|
23 | {
|
---|
24 | // Destroy via custom allocator.
|
---|
25 | }
|
---|
26 | };
|
---|
27 |
|
---|
28 |
|
---|
29 | int
|
---|
30 | main()
|
---|
31 | {
|
---|
32 | boost::movelib::unique_ptr<D, Deleter> ptr (new D);
|
---|
33 | offset_ptr<D> d = ptr.get(); // <- fails to compile
|
---|
34 | }
|
---|
35 |
|
---|