Saving boost :: bind functions to std :: map

I am creating a bunch of functions that effectively accomplish 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;
}

      

where Foo is a class. It's pretty simple. Now I really want to create a lot of variations on this, but tied to different sets. Then I want to store them to 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 am facing is determining the type of card. I thought it would be:

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

      

But compiled with MSVC 9.0 provides: error C2582: 'operator =' function is unavailable in 'boost::function<Signature>'

.

What exactly should the second template argument have?

+3


source to share


2 answers


And I solved it. I have included the wrong header file; instead:

#include <boost/function.hpp>



I have included things from the boost / function folder, for example:

#include <boost/function/function_fwd.hpp>

0


source


Using boost 1.49 and g ++ 4.4.4 I was able to do something very similar. Here is a code snippet.

typedef boost::function< void (SomeType) > CallbackType;

std::pair<std::string, CallbackType> NameCallbackPair;

      

Then I was able to assign it like this:



NameCallbackPair somePair(someString, boost::bind(&SomeClass::someMethod, this, _1));

      

Maybe it is something with MSVC9.

0


source







All Articles