Use BOOST_EXPLICIT_OPERATOR_BOOL for optional

I often have the problem that when I change a std::wstring to boost::optional<std::wstring> and the variable is used as a parameter with Boost.Format, the result silently changes from the string contents to "1".

This change prevents implicit conversion to bool if the compiler supports explicit conversion operators.
This commit is contained in:
Marcel Raad
2014-04-24 10:00:43 +02:00
committed by Andrzej Krzemienski
parent b4738ac07e
commit c7cf80e5df
8 changed files with 46 additions and 23 deletions

View File

@ -1086,8 +1086,8 @@ namespace optional_swap_test
//
void swap(boost::optional<class_whose_explicit_ctor_should_be_used> & x, boost::optional<class_whose_explicit_ctor_should_be_used> & y)
{
bool hasX = x;
bool hasY = y;
bool hasX(x);
bool hasY(y);
if ( !hasX && !hasY )
return;