Boost logo

Boost Users :

From: mr_lilirong_at_[hidden]
Date: 2001-11-21 23:21:48


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>
// <===


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net