Bind illustrated

原文地址:http://blog.think-async.com/2010/04/bind-illustrated.html


Asynchronous operations in Asio all expect a function object argument, the completion handler, which they invoke when the asynchronous operation completes. The signature of the handler depends on the type of operation. For example, a handler posted using io_service::post() must have the signature:

void handler();

while an asynchronous wait operation expects:

void handler(error_code ec);

and asynchronous read/write operations want:

void handler(error_code ec, size_t length);

Non-trivial applications will need to pass some context to the completion handler, such as a this pointer. One way to do this is to use a function object adapter like boost::bindstd::tr1::bind or (as of C++0x) std::bind.

Unfortunately, for many C++ programmers, bind represents a little bit of magic. This is not helped by the impenetrable compiler errors that confront you when you use it incorrectly. And, in my experience, the underlying concept (where some function arguments are bound up-front, while others are delayed until the point of call) can present quite a steep learning curve.

I have put together some diagrams to help explain how bind works. For clarity, I have taken a few liberties with C++ syntax (e.g. omitting the parameter types on the function call operator) and (over-)simplified bind's implementation. Finally, the examples are limited to those likely to be useful with Asio. Comments and suggestions welcome.


bind can be used to adapt a user-supplied function expecting one argument into a function object that takes zero arguments. The bound value (123 in this example) is stored in a function object and is automatically passed to the user-supplied function as required:


[ click images for full size ]

Binding an argument can be used to turn a class member function into a zero-argument function object. As you know, non-static member functions have an implicit this parameter. This means that an appropriate pointer needs to be bound into the function object:


Alternatively, the implicit this can be made explicit by adapting a member function into a function object taking one argument:


Function objects will often use both bound arguments and arguments supplied at the point of use. This can be done using member functions:


or non-member functions:


Sometimes the function object's point of use will supply arguments which are not required to call the target function. bind will automatically discard these surplus arguments:


The surplus argument(s) need not be the at the end of the function object signature:


Finally, bind allows you to the reorder arguments to adapt the target function to the necessary function object signature:

Rab GTPases serve as master regulators of membrane trafficking. They can be activated by guanine nucleotide exchange factors (GEF) and be inactivated by GTPase-activating proteins (GAPs). The roles of some GAPs have been explored in Saccharomyces cerevisiae, but are largely unknown in filamentous fungi. Here, we investigated the role of GAP Gyp3 gene, an ortholog of S. cerevisiae Gyp3, in an entomopathogenic fungus, Metarhizium acridum. We found that MaGyp3 is mainly localized to the endoplasmic reticulum (ER) of vegetative hyphae, nuclei of mature conidia, and both ER and nuclei in invasive hyphae. Lack of MaGyp3 caused a decreased tolerance to hyperosmotic stress, heat-shock and UV-B radiation. Moreover, the ΔMaGyp3 mutant showed a significantly decreased pathogenicity owing to delayed germination, reduced appressorium-mediated penetration and impaired invasive growth. Loss of MaGyp3 also caused impaired fungal growth, advanced conidiation and defects in utilization of carbon and nitrogen sources, while overexpression of MaGyp3 exhibited delayed conidiation on nutrient-rich medium and conidiation pattern shift from microcycle conidiation to normal conidiation on nutrient-limited medium. Mavib-1, a tanscription factor invloved in conidiation by affecting nutrient utilizaiton, can directly bind to the promoter of MaGyp3. ΔMaGyp3 and ΔMavib-1 mutants shared similar phenotypes, and overexpression mutants of MaGyp3 and Mavib-1 (Mavib-1-OE) exhibited similar phenotypes in growth, conidiation and pathogenicity. Reintroduction of the Magyp3 driven by strong promoter gpd in ΔMavib-1 mutant recovered the defects in growth and conidiation for dysfunction of Mavib1. Taken together, our findings uncovered the role of GAP3 in a filamentous pathogenic fungus and and illustrated the upstream regulatory mechanism by direct interaction with Mavib-1.
最新发布
02-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值