本文介绍了什么是boost :: bind的返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个函数的binder保存到一个变量中,通过利用它的操作符重载设施在下面的代码中重复使用它。这里是实际做我想要的代码:

I want to save the "binder" of a function to a variable, to use it repetitively in the following code by exploiting its operator overloading facilities. Here is the code that actually does what I want:

 
  1. std::tr1::function<>
  2. BOOST_AUTO()
  3. c++0x 'auto' keywords (Type Inference)
    • it's close cousing decltype() can help you move further



1。



1.

std::tr1::function<int> f; // can be assigned from a function pointer, a bind_expression, a function object etc

int realfunc();
int realfunc2(int a);

f = &realfunc;
int dummy;
f = tr1::bind(&realfunc2, dummy);



2。



BOOST_AUTO支持语法c ++ 0x auto没有编译器c ++ 0x支持:

2.

BOOST_AUTO() aims to support the semantics of c++0x auto without compiler c++0x support:

BOOST_AUTO(f,boost::bind(&T::some_complicated_method, _3, _2, "woah", _2));



3。



与编译器支持:

3.

Essentially the same but with compiler support:

template <class T> struct DoWork { /* ... */ };

auto f = boost::bind(&T::some_complicated_method, _3, _2, "woah", _2));

DoWork<decltype(T)> work_on_it(f); // of course, using a factory would be _fine_

注意,auto可能是为这种类型发明的的情况:实际类型是你不想知道,并且可能因编译器/平台/库而异

Note that auto has probably been invented for this kind of situation: the actual type is a 'you don't want to know' and may vary across compilers/platforms/libraries

这篇关于什么是boost :: bind的返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:59