How to dereference an iterator using boost::bind

Discussion in 'C++' started by Stone Free, Sep 23, 2009.

  1. Stone Free

    Stone Free Guest

    If I have a routine that partitions a vector based on the data
    recorded in a supplemental map, and the preconditions to entering the
    routine are that every element in the vector exists in the map. How
    do I do the following exclusively using boost::bind?

    #include "stdafx.h"
    #include <string>
    #include <map>
    #include <vector>
    #include <functional>
    #include <algorithm>
    #include <boost/bind.hpp>


    typedef int DWORD;
    typedef std::pair<std::string, bool> user_info;
    typedef std::map<DWORD, user_info> USER_MAP;
    typedef std::vector<DWORD> VEC_STAFF;


    struct current_user_check
    : public std::unary_function<USER_MAP::const_iterator, bool>
    {
    bool operator()(const argument_type & val) const
    {
    return val->second.second;
    }
    };

    void SomeObject::partitionActiveUsers()
    {
    //m_users - Gathers staff details from DB
    //m_users.GetStaff(); returns a vector of IDs
    //USER_MAP m_Users;
    //...

    VEC_STAFF Staff;//(m_users.GetStaff());
    VEC_STAFF::const_iterator itCurEnd = stable_partition(Staff.begin(),
    Staff.end(), (boost::bind(current_user_check(), boost::bind
    (&USER_MAP::find, &m_Users, _1))));
    }
    Stone Free, Sep 23, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Toby Bradshaw
    Replies:
    6
    Views:
    1,740
    Kai-Uwe Bux
    Jun 2, 2006
  2. Replies:
    0
    Views:
    589
  3. Carsten Haese

    Re: How to "dereference" an iterator?

    Carsten Haese, Oct 11, 2007, in forum: Python
    Replies:
    1
    Views:
    314
    Steven D'Aprano
    Oct 11, 2007
  4. Christopher
    Replies:
    1
    Views:
    807
    Yakov Gerlovin
    Oct 5, 2011
  5. Mark
    Replies:
    1
    Views:
    426
    Jeff Flinn
    Nov 25, 2012
Loading...

Share This Page