function_base.hpp

来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 661 行 · 第 1/2 页

HPP
661
字号
        { return f.empty(); }      template<typename Function, typename Functor>        bool        compare_not_equal(const Function& f, const Functor&, int,                          mpl::bool_<true>)        { return !f.empty(); }      template<typename Function, typename Functor>        bool        compare_equal(const Function& f, const Functor& g, long,                      mpl::bool_<false>)        {          if (const Functor* fp = f.template target<Functor>())            return function_equal(*fp, g);          else return false;        }      template<typename Function, typename Functor>        bool        compare_equal(const Function& f, const reference_wrapper<Functor>& g,                      int, mpl::bool_<false>)        {          if (const Functor* fp = f.template target<Functor>())            return fp == g.get_pointer();          else return false;        }      template<typename Function, typename Functor>        bool        compare_not_equal(const Function& f, const Functor& g, long,                          mpl::bool_<false>)        {          if (const Functor* fp = f.template target<Functor>())            return !function_equal(*fp, g);          else return true;        }      template<typename Function, typename Functor>        bool        compare_not_equal(const Function& f,                          const reference_wrapper<Functor>& g, int,                          mpl::bool_<false>)        {          if (const Functor* fp = f.template target<Functor>())            return fp != g.get_pointer();          else return true;        }#endif // BOOST_NO_SFINAE    } // end namespace function  } // end namespace detail/** * The function_base class contains the basic elements needed for the * function1, function2, function3, etc. classes. It is common to all * functions (and as such can be used to tell if we have one of the * functionN objects). */class function_base{public:  function_base() : manager(0)  {    functor.obj_ptr = 0;  }  // Is this function empty?  bool empty() const { return !manager; }  template<typename Functor>    Functor* target()    {      if (!manager) return 0;      detail::function::any_pointer result =        manager(detail::function::make_any_pointer(&typeid(Functor)),                detail::function::check_functor_type_tag);      if (!result.obj_ptr) return 0;      else {        typedef typename detail::function::get_function_tag<Functor>::type tag;        return get_functor_pointer<Functor>(tag(), 0);      }    }  template<typename Functor>    const Functor* target() const    {      if (!manager) return 0;      detail::function::any_pointer result =        manager(detail::function::make_any_pointer(&typeid(Functor)),                detail::function::check_functor_type_tag);      if (!result.obj_ptr) return 0;      else {        typedef typename detail::function::get_function_tag<Functor>::type tag;        return get_functor_pointer<Functor>(tag(), 0);      }    }  template<typename F>    bool contains(const F& f) const    {      if (const F* fp = this->template target<F>()) {        return function_equal(*fp, f);      } else {        return false;      }    }#if defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3  // GCC 3.3 and newer cannot copy with the global operator==, due to  // problems with instantiation of function return types before it  // has been verified that the argument types match up.  template<typename Functor>    BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)    operator==(Functor g) const    {      if (const Functor* fp = target<Functor>())        return function_equal(*fp, g);      else return false;    }  template<typename Functor>    BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)    operator!=(Functor g) const    {      if (const Functor* fp = target<Functor>())        return !function_equal(*fp, g);      else return true;    }#endifpublic: // should be protected, but GCC 2.95.3 will fail to allow access  detail::function::any_pointer (*manager)(    detail::function::any_pointer,    detail::function::functor_manager_operation_type);  detail::function::any_pointer functor;private:  template<typename Functor>    Functor* get_functor_pointer(detail::function::function_ptr_tag, int)    { return reinterpret_cast<Functor*>(&functor.func_ptr); }  template<typename Functor, typename Tag>    Functor* get_functor_pointer(Tag, long)    { return static_cast<Functor*>(functor.obj_ptr); }  template<typename Functor>    const Functor*    get_functor_pointer(detail::function::function_ptr_tag, int) const    { return reinterpret_cast<const Functor*>(&functor.func_ptr); }  template<typename Functor, typename Tag>    const Functor* get_functor_pointer(Tag, long) const    { return static_cast<const Functor*>(functor.const_obj_ptr); }};/** * The bad_function_call exception class is thrown when a boost::function * object is invoked */class bad_function_call : public std::runtime_error{public:  bad_function_call() : std::runtime_error("call to empty boost::function") {}};#ifndef BOOST_NO_SFINAEinline bool operator==(const function_base& f,                       detail::function::useless_clear_type*){  return f.empty();}inline bool operator!=(const function_base& f,                       detail::function::useless_clear_type*){  return !f.empty();}inline bool operator==(detail::function::useless_clear_type*,                       const function_base& f){  return f.empty();}inline bool operator!=(detail::function::useless_clear_type*,                       const function_base& f){  return !f.empty();}#endif#ifdef BOOST_NO_SFINAE// Comparisons between boost::function objects and arbitrary function objectstemplate<typename Functor>  inline bool operator==(const function_base& f, Functor g)  {    typedef mpl::bool_<(is_integral<Functor>::value)> integral;    return detail::function::compare_equal(f, g, 0, integral());  }template<typename Functor>  inline bool operator==(Functor g, const function_base& f)  {    typedef mpl::bool_<(is_integral<Functor>::value)> integral;    return detail::function::compare_equal(f, g, 0, integral());  }template<typename Functor>  inline bool operator!=(const function_base& f, Functor g)  {    typedef mpl::bool_<(is_integral<Functor>::value)> integral;    return detail::function::compare_not_equal(f, g, 0, integral());  }template<typename Functor>  inline bool operator!=(Functor g, const function_base& f)  {    typedef mpl::bool_<(is_integral<Functor>::value)> integral;    return detail::function::compare_not_equal(f, g, 0, integral());  }#else#  if !(defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ <= 3)// Comparisons between boost::function objects and arbitrary function// objects. GCC 3.3 and before has an obnoxious bug that prevents this// from working.template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator==(const function_base& f, Functor g)  {    if (const Functor* fp = f.template target<Functor>())      return function_equal(*fp, g);    else return false;  }template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator==(Functor g, const function_base& f)  {    if (const Functor* fp = f.template target<Functor>())      return function_equal(g, *fp);    else return false;  }template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator!=(const function_base& f, Functor g)  {    if (const Functor* fp = f.template target<Functor>())      return !function_equal(*fp, g);    else return true;  }template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator!=(Functor g, const function_base& f)  {    if (const Functor* fp = f.template target<Functor>())      return !function_equal(g, *fp);    else return true;  }#  endiftemplate<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator==(const function_base& f, reference_wrapper<Functor> g)  {    if (const Functor* fp = f.template target<Functor>())      return fp == g.get_pointer();    else return false;  }template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator==(reference_wrapper<Functor> g, const function_base& f)  {    if (const Functor* fp = f.template target<Functor>())      return g.get_pointer() == fp;    else return false;  }template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator!=(const function_base& f, reference_wrapper<Functor> g)  {    if (const Functor* fp = f.template target<Functor>())      return fp != g.get_pointer();    else return true;  }template<typename Functor>  BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor, bool)  operator!=(reference_wrapper<Functor> g, const function_base& f)  {    if (const Functor* fp = f.template target<Functor>())      return g.get_pointer() != fp;    else return true;  }#endif // Compiler supporting SFINAEnamespace detail {  namespace function {    inline bool has_empty_target(const function_base* f)    {      return f->empty();    }#if BOOST_WORKAROUND(BOOST_MSVC, <= 1310)    inline bool has_empty_target(const void*)    {      return false;    }#else    inline bool has_empty_target(...)    {      return false;    }#endif  } // end namespace function} // end namespace detail} // end namespace boost#undef BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL#undef BOOST_FUNCTION_COMPARE_TYPE_ID#endif // BOOST_FUNCTION_BASE_HEADER

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?