1

我发现了这个使用升压信号的 C++ 代码,我正在尝试理解它。

// A boost::signal wrapper structure 
template <typename Signature>
struct SignalBase : public boost::noncopyable
{
    typedef boost::function_traits< Signature >        SignatureTraits;

    typedef boost::signal<Signature>                   SignalType;
    typedef typename SignalType::slot_function_type    SlotFunctionType;
    typedef typename SignalType::result_type           ResultType;
    typedef boost::signals::connection                 ConnectionType;

    SignalBase() : m_signal() {};
    virtual ~SignalBase() {};

protected:
    SignalType m_signal;
};


// I use a specialization of this template for an arity of 1.
// The template generates the correct function call operator for the arity of the signal.
template<int Arity, typename Signature>
struct SelArity : public SignalBase<Signature> {};

// Specialization
template<typename Signature>
struct SelArity< 1, Signature> : public SignalBase<Signature>
{
    typedef SignalBase<Signature> BaseType;
    inline typename BaseType::ResultType operator()(typename BaseType::SignatureTraits::arg1_type arg )
    {
        return BaseType::m_signal( arg );
    }
};

我不知道SelArity函子会返回什么。据我了解m_signal是一种可以声明信号的类型,该信号将能够连接到带有Signature签名的函数。怎么可能有类型作为参数?(见return BaseType::m_signal( arg );)什么是代表的类型ResultType?我将如何使用SelArity仿函数返回的对象?

4

1 回答 1

1

不,m_signal不是类型,它是 class 的实例SignalType,即boost::signal<Signature>.

SelArityfunctor 实际上m_signal使用 1 个参数调用并返回其返回值。

(我不知道所有这些包装器需要什么。)

于 2013-02-02T21:42:12.653 回答