OpenDDS
Snapshot(2023/04/28-20:55)
|
#include <dds/Versioned_Namespace.h>
Go to the source code of this file.
Classes | |
class | OpenDDS::DCPS::SafeBoolBase |
class | OpenDDS::DCPS::SafeBool_T< DerivedNonVirtual > |
class | OpenDDS::DCPS::SafeBool_T< void > |
Namespaces | |
OpenDDS | |
The Internal API and Implementation of OpenDDS. | |
OpenDDS::DCPS | |
Functions | |
template<typename X , typename Y > | |
bool | OpenDDS::DCPS::operator== (const SafeBool_T< X > &x, const SafeBool_T< Y > &) |
template<typename X , typename Y > | |
bool | OpenDDS::DCPS::operator!= (const SafeBool_T< X > &x, const SafeBool_T< Y > &) |
Implements the "Safe Bool" idiom, which is a safer alternative to operator bool. Based on: https://www.artima.com/articles/the-safe-bool-idiom TLDR: We may want to be able to use operator bool()
to check an object's abstract truthfulness using if (object) {...}
, but that opens up implicit casting and comparisons that come with the bool type that are almost certainly not desired, like int count = object
. This is achieved via the BoolType function pointer which isn't actually called, but is the only boolean-ish thing the type can be implicitly converted to using the BoolType operator.
If you want the boolean test function to be virtual, implement it as: virtual bool boolean_test() const; and derive the class from SafeBool_T with no template argument: class YourClass : public SafeBool_T<>.
If you do NOT want the boolean test function to be virtual, implement it as: bool boolean_test() const; and derive the class from SafeBool_T with the class as the template argument: class YourClass : public SafeBool_T<YourClass>.
Definition in file SafeBool_T.h.