[optional] operator <<

Hello, I've just noticed that the following code might be missleading: boost::optional<int> opt; opt = 0; std::cout << opt; If boost/optional/optional_io.hpp is not included, the above code outputs "1" - because boost::optional is implicitly convertible to bool. Maybe it's worth either including boost/optional/optional_io.hpp in boost/optional.hpp or making some trick to generate compiler error if operator <<() used and optional_io.hpp is not included?

On Feb 19, 2009, at 5:45 AM, Igor R wrote:
I've just noticed that the following code might be missleading:
boost::optional<int> opt; opt = 0; std::cout << opt;
It's a known bug, but there's a patch to fix it in Trac: https://svn.boost.org/trac/boost/ticket/2103 -- Andrew Troschinetz Applied Research Laboratories

I've just noticed that the following code might be missleading:
boost::optional<int> opt; opt = 0; std::cout << opt;
It's a known bug, but there's a patch to fix it in Trac: https://svn.boost.org/trac/boost/ticket/2103
Ok, I see now... Thank you.
participants (2)
-
Andrew Troschinetz
-
Igor R