
Yuval Ronen wrote:
As I explained in another post in this thread, I think boost::optional is the ultimate solution to the active/inactive state problem, so the class itself can still have single phase construction.
There is a lot about boost::optional that I am not entirely happy about, but we dont really want to get into that on this thread, however the general idea of using optional or a similar facility is still very interesting. I imagine that the idea would be to refactor the current class with active/inactive state into two separate classes. The long lived object (needed for complex structural reasons) that would operate as normal, but all the active-dependent interface would be moved to the new/separate class and accessed through a member function returning an optional<T> (or similar). I can see where this would make excellent sense in several of my applications. To optimise access inside tight loops you could assign the optional<T> to a T& - and so only be checking existence at the start... as opposed to my present problem of having to choose between assertion or exception checking at the top of each top-level class function. Yes, I like the thought very much. Thank you. -- Geoff Worboys Telesis Computing