std::bind问题

C++语言 码拜 8年前 (2016-05-21) 948次浏览
有人知道std::bind的准确返回类型么。
不要说auto,本人的需求是要知道准确返回类型。
原因是本人想用boost::any来存储这个std::bind的返回值。
但解boost::any的时候,需要明确告知转换的类型。
不然没法使用,这个问题困扰挺长时间了,一直没搞定。
解决方案

100

#include <boost/any.hpp>
#include <iostream>
#include <functional>
using namespace std;
using namespace boost;
class A
{
public:
	void test(int n)
	{
		cout << n << endl;
	}
};
int main()
{
	A a;
	//装进去
	any fn1 = bind(&A::test, &a, placeholders::_1);

	//拿出来用
	_Bind<1, void, struct std::_Pmf_wrap<void(__thiscall A::*)(int), void, class A, int>, class A *, class std::_Ph<1> &> fn2 = any_cast<_Bind<1, void, struct std::_Pmf_wrap<void(__thiscall A::*)(int), void, class A, int>, class A *, class std::_Ph<1> &>>(fn1);
	fn2(50);

	return 0;
}

直接用确切类型也是可以的


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明std::bind问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)