如何提振一般在幕后工作的结合? [英] How does boost bind work behind the scenes in general?

查看:194
本文介绍了如何提振一般在幕后工作的结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无需花费很长的时间审查升压源$ C ​​$ C,能有人给我的刺激绑定是如何实现快速纲要?

Without spending a long time reviewing the boost source code, could someone give me a quick rundown of how boost bind is implemented?

推荐答案

我喜欢这片绑定来源:

template<class R, class F, class L> class bind_t
{
public:

    typedef bind_t this_type;

    bind_t(F f, L const & l): f_(f), l_(l) {}

#define BOOST_BIND_RETURN return
#include <boost/bind/bind_template.hpp>
#undef BOOST_BIND_RETURN

};

告诉您几乎所有你需要知道的,真的。

Tells you almost all you need to know, really.

bind_template 头扩大到内联操作符()定义的列表。例如,最简单的:

The bind_template header expands to a list of inline operator() definitions. For example, the simplest:

result_type operator()()
{
    list0 a;
    BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}

我们可以看到这样的线是 BOOST_BIND_RETURN 宏扩展到收益在这一点上更像返回L_(类型...)

We can see the BOOST_BIND_RETURN macro expands to return at this point so the line is more like return l_(type...).

在一个参数的版本是在这里:

The one parameter version is here:

template<class A1> result_type operator()(A1 & a1)
{
    list1<A1 &> a(a1);
    BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}

这是pretty相似。

It's pretty similar.

listN 类的参数列表包装。有很多的魔渊会在这里,我真的不明白太多,但。他们还超载操作符()调用神秘展开功能。忽略一些特定的编译器过载,它不会做了很多:

The listN classes are wrappers for the parameter lists. There is a lot of deep magic going on here that I don't really understand too much though. They have also overloaded operator() that calls the mysterious unwrap function. Ignoring some compiler specific overloads, it doesn't do a lot:

// unwrap

template<class F> inline F & unwrap(F * f, long)
{
    return *f;
}

template<class F> inline F & unwrap(reference_wrapper<F> * f, int)
{
    return f->get();
}

template<class F> inline F & unwrap(reference_wrapper<F> const * f, int)
{
    return f->get();
}

的命名规则似乎是:˚F是函数的参数为​​绑定的类型。 研究是返回类型。 往往是参数类型的列表。也有很多的并发症,因为有不同数量的参数没有少于九个重载。最好不要纠缠于太多。

The naming convention seems to be: F is the type of the function parameter to bind. R is the return type. L tends to be a list of parameter types. There are also a lot of complications because there are no less than nine overloads for different numbers of parameters. Best not to dwell on that too much.

这篇关于如何提振一般在幕后工作的结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆