S
Stone Free
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace boost::bind;
typedef int DWORD;
typedef std:air<std::string, bool> user_info;
typedef std::map<DWORD, user_info> USER_MAP;
typedef std::vector<DWORD> VEC_STAFF;
int main(int argc, _char* argv[])
{
USER_MAP m_Users;
VEC_STAFF Staff;
...
...
VEC_STAFF::iterator it = std:artition(Staff.begin(), Staff.end(),
(bind(&USER_MAP::find, m_Users, _1) != m_Users.end()));
return 0;
}
What I wanted to code to do is that for every entry in the Staff
vector it should check to see whether that user id was present in the
map, and if so move those items to the front.
I have an example using a functor that works as I hoped the above code
would, but the bind version is obviously not doing what I think its
doing.
struct InUsersMap : public
std::unary_function<USER_MAP::key_type,bool>
{
InUsersMap(USER_MAP & theMap, USER_MAP::const_iterator end)
: m_theMap(theMap)
{
}
inline bool operator()(CSecurePatients::USER_MAP::key_type& id) const
{
return m_theMap.find(id) != m_theMap.end();
}
private:
const USER_MAP &m_theMap;
}
#include <set>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace boost::bind;
typedef int DWORD;
typedef std:air<std::string, bool> user_info;
typedef std::map<DWORD, user_info> USER_MAP;
typedef std::vector<DWORD> VEC_STAFF;
int main(int argc, _char* argv[])
{
USER_MAP m_Users;
VEC_STAFF Staff;
...
...
VEC_STAFF::iterator it = std:artition(Staff.begin(), Staff.end(),
(bind(&USER_MAP::find, m_Users, _1) != m_Users.end()));
return 0;
}
What I wanted to code to do is that for every entry in the Staff
vector it should check to see whether that user id was present in the
map, and if so move those items to the front.
I have an example using a functor that works as I hoped the above code
would, but the bind version is obviously not doing what I think its
doing.
struct InUsersMap : public
std::unary_function<USER_MAP::key_type,bool>
{
InUsersMap(USER_MAP & theMap, USER_MAP::const_iterator end)
: m_theMap(theMap)
{
}
inline bool operator()(CSecurePatients::USER_MAP::key_type& id) const
{
return m_theMap.find(id) != m_theMap.end();
}
private:
const USER_MAP &m_theMap;
}