在std :: map中存储boost :: bind函数 [英] Storing boost::bind functions in a std::map

查看:321
本文介绍了在std :: map中存储boost :: bind函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一堆函数,它们都有效地做同样的事情:

I'm creating a bunch of functions which all effectively do the same thing:

long Foo::check(long retValue, unsigned toCheck, const std::set<unsigned>& s)
{
    auto it = s.find(toCheck);
    return (it == s.end()) ? -retValue : retValue;
}

其中Foo是一个类。到目前为止所有相当简单。现在,我真的想创建很多变体,但绑定到不同的集合。然后我想把它们存储在std :: map中。所以,使用boost :: bind和boost :: function,做一些类似:

where Foo is a class. All fairly simple so far. Now, I effectively want to create a lot of variants on this, but bound to different sets. I then want to store these in a std::map. So, using boost::bind and boost::function, do something like:

void Foo::addToMap(unsigned option, const std::set<unsigned>& currentSet)
{
    someMap[option] = boost::bind(&Foo::check, this, _1, _2, currentSet);
}

我遇到的问题是尝试定义地图的类型。我认为这是:

The problem I'm having is trying to define the type of the map. I thought it would be:

std::map<unsigned, boost::function<long (long, unsigned)> > someMap;



<函数在'boost :: function< Signature>'中不可用。

映射的第二个模板参数究竟应该是什么?

What exactly should the second template argument to map be?

推荐答案

我解决了。我包括错误的头文件;而不是:

Ah I solved it. I was including the wrong header file; instead of:

#include< boost / function.hpp>

我在boost / function文件夹中包含了以下内容:

I was including things from the boost/function folder like:

#include< boost / function / function_fwd.hpp> ;

这篇关于在std :: map中存储boost :: bind函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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