[問題] Loki的Functor

看板C_and_CPP (C/C++)作者 (老王)時間15年前 (2011/01/10 23:10), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
template <class ParentFunctor, typename Fun> class FunctorHandler : public ParentFunctor::Impl { typedef typename ParentFunctor::Impl Base; public: typedef typename Base::ResultType ResultType; typedef typename Base::Parm1 Parm1; typedef typename Base::Parm2 Parm2; typedef typename Base::Parm3 Parm3; FunctorHandler(const Fun& fun) : f_(fun) {} // 以下略.... }; template <typename R = void, class TList = NullType> class Functor { public: // Handy type definitions for the body type typedef FunctorImpl<R, TList> Impl; typedef R ResultType; typedef TList ParmList; typedef typename Impl::Parm1 Parm1; typedef typename Impl::Parm2 Parm2; typedef typename Impl::Parm3 Parm3; // Member functions // ........ template <typename Fun> Functor(Fun fun) : spImpl_(new FunctorHandler<Functor, Fun>(fun)) {} ^^^^^^^ // 以下略.... private: std::auto_ptr<Impl> spImpl_; }; 最近在看modern c++ design這本書的generalized functors 有一個地方一直不懂 那就是為什麼在new FunctorHandler時的第一個template參數要用Functor 而不是Functor<ResultType, ParmList>? 此處讓我感到困惑的點是FunctorHandler的第一個template參數既然是class 那為何我們可以傳給他一個template class? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.176.189

01/11 00:47, , 1F
剛剛測試 傳Functor<ResultType, ParmList>也是可行的
01/11 00:47, 1F
文章代碼(AID): #1DAo5Spv (C_and_CPP)
文章代碼(AID): #1DAo5Spv (C_and_CPP)