Can you explain for me what the typedef here is doing and what the purpose is?
class C
{
public:
...
typedef bool (C::*implementation_defined_bool_type)(bool) const;
operator implementation_defined_bool_type() const {
return _spi ? &C::isPersistent : 0;
}
};
typedefs a pointer to a const member function of a typeC, which takes aboolas input parameter and also returns abool.While,
Takes in an object of type
Cand returns a typeimplementation_defined_bool_type.It is known as an Conversion Operator.
It implements the “Safe Bool Idiom”, which aims to validate an object in a boolean context.
Note that the Safe Bool Idiom is obsolete with the C++11 Standard.
Good Read:
The Safe Bool Idiom