
Frank Laub wrote:
I hadn't realized that this was an improper usage of optional. I returned 'false' because it felt like a 'natural' thing to return as that of a failure. Because the compiler and my tests showed this to work, I figured optional had a special bool constructor or something. I've noticed others use a 'none' type. I suppose the default ctor is the preferred way?
AFAIK, there's no difference between the default constructor and the 'none' constructor. They both construct the optional in the 'un-initialized' state, and you can use whichever you want. Using any other constructor (copy constructor aside) would try to construct the optional's value_type using the argument to the constructor, and put the optional in an 'initialized' state. Sending 'false' as a constructor argument falls into the second category, which is not what you wanted...
Thanks for the heads up.
My pleasure.