Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 459883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:49:02+00:00 2026-05-12T22:49:02+00:00

Searching in the second value of a map i use somthing like the following:

  • 0

Searching in the second value of a map i use somthing like the following:

typedef std::map<int, int> CMyList;
static CMyList myList;

template<class t> struct second_equal
{
    typename typedef t::mapped_type mapped_type;
    typename typedef t::value_type value_type;

    second_equal(mapped_type f) : v(f)   {};
    bool operator()(const value_type &a) { return a.second == v;};

    mapped_type v;
};
...    
int i = 7;
CMyList::iterator it = std::find_if(myList.begin(), myList.end(), 
                                    second_equal<CMyList>(i));

Question: How can i do such a find in a single line without supplying a self written template?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:49:02+00:00Added an answer on May 12, 2026 at 10:49 pm

    Use a selector to select the first or the second element from the value_type that you get from the map.
    Use a binder to bind the value (i) to one of the arguments of the std::equal_to function.
    Use a composer to use the output of the selector as the other argument of the equal_to function.

    //stl version
    CMyList::iterator it = std::find_if(
        myList.begin(), 
        myList.end(), 
        std::compose1(
            std::bind2nd(equal_to<CMyList::mapped_type>(), i), 
            std::select2nd<CMyList::value_type>())) ;
    
    //Boost.Lambda or Boost.Bind version
    CMyList::iterator it = std::find_if(
        myList.begin(), 
        myList.end(), 
        bind( &CMyList::mapped_type::second, _1)==i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Searching for values that uses the same value Example SELECT Name, UnitPrice, Quantity, Color
Searching from google.com, like www.abc.com Search Result Rank the pages like Title..... Description... www.abc.com
Searching online, I have found the following routine for calculating the sign of a
Searching a Python dictionary based on the value first, to get a key output
As you can see in the following Fiddle: http://jsfiddle.net/EvWc4/3/ , I'm currently searching a
Extracting the href value from the following sample HTML code is straight forward if
I would like to build a Django app that allows searching for a movie
I would like to have a HashMap with only one key-value object. I have
Searching around I haven't found any recent answers to this question. The other answers
Searching here I found that this question was already asked , but I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.