Please consider following struct:
struct ThingThatWillGoInSharedMemory {
boost::optional<int> opt_value;
};
I'm using boost::interprocess to create the shared memory area. My understanding of boost::optional was that it was a discriminated union rather than a nullable pointer. As a counter-example things like std::map and std::vector which use the heap need an explicit allocator to use them in interprocess memory, but boost::optional, I was fairly sure does not use the heap and is equivalent to writing:
struct ThingThatWillGoInSharedMemory {
bool value_initialised;
int value;
}
So it can be used out of the box. I'd be delighted if someone confirms this - I didn't see that the interprocess case was explicitly mentioned in the boost::optional docs, only implied.