
Fernando Cacciola wrote:
Hi Jeffrey,
In my experience, changing the class layout based on a preprocessor switch is a very bad idea since it breaks binary compatibility with libraries compiled with a different switch, so I strongly suggest you/we find a better solution.
I agree. This is probably the largest drawback. I'll look further.
If this functionality is really really needed (read below), I would create a *different* template class to offer it. One such debugger-friendly optional<> would replace (rather than add) the bool field with a T* field (which would be set to NULL when uninitialized). A different template class makes sure that binary-differing optional's don't mix accidentally (in the same wa a policy-based design does it).
I'll see what I can do with this. Perhaps this other class will wrap the real boost::optional, providing the same interface, and giving an additional debug value. This would make it easier to keep the two classes in sync.
But I'm curious: doesn't a simple dynamic watch, like "*opt", works?? That calls a method on the object, yes, but debuggers have been able to do that for decades now.
Quite honestly, I couldn't answer this before I tried it. Using the "Immediate Window" in VC8 gives the error "CXX0034: Error: types incompatible with operator." Now this is a legitimate debugger problem. Thanks for the idea, Jeff Faust