[問題] Loki的Functor
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
01/11 00:47, 1F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
11
38