【发布时间】:2013-02-02 20:06:12
【问题描述】:
我发现了这个使用升压信号的 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 functor 返回的对象?
【问题讨论】:
标签: c++ boost metaprogramming template-meta-programming boost-signals