Permalink
Browse files

correct use of boost::indeterminate

  • Loading branch information...
1 parent bef7d1a commit 8f0c52109d5bcddd4ab6c4525338f246c53364e2 @dougma dougma committed Apr 17, 2013
@@ -129,20 +129,18 @@ bool PluginCore::setReady()
bool PluginCore::isWindowless()
{
- if (m_windowLessParam != boost::indeterminate) {
- return m_windowLessParam;
- } else {
+ if (boost::indeterminate(m_windowLessParam)) {
+ // initialise m_windowLessParam (defaulting to not windowless)
+ m_windowLessParam = false;
FB::VariantMap::iterator itr = m_params.find("windowless");
if (itr != m_params.end()) {
try {
m_windowLessParam = itr->second.convert_cast<bool>();
- return m_windowLessParam;
} catch (const FB::bad_variant_cast& ex) {
FB_UNUSED_VARIABLE(ex);
}
- }
+ }
}
- m_windowLessParam = false;
return m_windowLessParam;
}
@@ -198,8 +198,8 @@ bool URI::isLocalhost() const {
if (fnd->first == boost::asio::ip::address_v4::loopback().to_string()) {
return true;
}
- static boost::tribool lastResult = indeterminate;
- if (lastResult != indeterminate) return lastResult;
+ static boost::tribool lastResult(boost::indeterminate);
+ if (!boost::indeterminate(lastResult)) return lastResult;
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
@@ -51,7 +51,7 @@ const FB::FBVoid FB::variant_detail::conversion::convert_variant( const FB::vari
}
FB::variant FB::variant_detail::conversion::make_variant(const boost::tribool& val) {
- if (val == boost::indeterminate)
+ if (boost::indeterminate(val))
return FB::variant();
else
return (bool)val;
@@ -201,6 +201,31 @@ TEST(VariantOptionalTest)
CHECK(!dblVal);
}
}
+TEST(VariantTriBool)
+{
+ PRINT_TESTNAME;
+ using namespace FB;
+
+ variant e;
+ variant i = boost::tribool(boost::indeterminate);
+ variant t = boost::tribool(true);
+ variant f = boost::tribool(false);
+
+ // boost::indeterminate is converted to an empty variant
+ // empty variants can be converted back to boost::tribool
+ CHECK(i.empty());
+ CHECK(boost::indeterminate(i.convert_cast<boost::tribool>()));
+ CHECK(boost::indeterminate(e.convert_cast<boost::tribool>()));
+ CHECK(t.convert_cast<boost::tribool>() == boost::tribool(true));
+ CHECK(f.convert_cast<boost::tribool>() == boost::tribool(false));
+ CHECK(t.convert_cast<bool>() == true);
+ CHECK(f.convert_cast<bool>() == false);
+
+ variant bt = bool(true);
+ variant bf = bool(false);
+ CHECK(bt.convert_cast<boost::tribool>());
+ CHECK(!bf.convert_cast<boost::tribool>());
+}
TEST(VariantToBoostVariantConversionTest)
{
PRINT_TESTNAME;

0 comments on commit 8f0c521

Please sign in to comment.