Is there a standard C++ function object for taking apart a std::pair?

前端 未结 6 1596
粉色の甜心
粉色の甜心 2020-12-20 14:06

Does anyone know if there\'s a de-facto standard (i.e., TR1 or Boost) C++ function object for accessing the elements of a std::pair? Twice in the past 24 hours I\'ve wished

6条回答
  •  自闭症患者
    2020-12-20 14:46

    What about using combinations of different containers.

    For example when I wanted to partition a vector into items contained in a supplemental map and items that where not contained in the supplemental map I used the following:

    typedef int DWORD; 
    typedef std::pair user_info; 
    typedef std::map USER_MAP; 
    typedef std::vector VEC_STAFF; 
    
    VEC_STAFF::iterator it = std::partition(Staff.begin(), Staff.end(), (bind(&USER_MAP::find, m_Users, _1) != m_Users.end()));
    

    Now I have a second problem - during the running of the application the status bool of user_info can change, and later on I want to re-partition the vector with items that have a status bool of true rather than just being contained in the supplemental map.

    However I seem to have a problem accessing the second item of a nested pair.

    I tried the following but I cannot seem to access the nested pair!

    CActiveUsers::VEC_STAFF::const_iterator itCurEnd = partition(Staff.begin(), Staff.end(), bind(&USER_MAP::value_type::second::second, bind(&USER_MAP::find, &m_Users, _1)) == true); 
    

提交回复
热议问题