
22 Nov
2001
22 Nov
'01
4:21 a.m.
Hi, The following code is excerpted from Boost.Function. I just don't unstanding it. Why use "safe_bool"? What's the advantage? Can any one explain it to me? Thanks. // code from <boost/function/function_base.hpp> // ===> private: struct dummy { void nonnull() {}; }; typedef void (dummy::*safe_bool)(); public: operator safe_bool () const { return (this->empty())? 0 : &dummy::nonnull; } safe_bool operator!() const { return (this->empty())? &dummy::nonnull : 0; } // code from <boost/function/function_base.hpp> // <===