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

  • SEARCH
  • Home
  • 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 8405863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:56:32+00:00 2026-06-09T22:56:32+00:00

i recently came across a part of code which looks like as follows: static

  • 0

i recently came across a part of code which looks like as follows:

static typename handle_set::iterator find(T* p)
        {
        return std::find_if(handles().begin(), handles().end(), [p](const std::unique_ptr<T,D>& l) { return l.get() == p; });
        }

where

typedef typename std::set<std::unique_ptr<T,D>> handle_set;
    static handle_set& handles(void)
    {
        static handle_set h_;

        return h_;
    }

my question is about this part:

[p](const std::unique_ptr<T,D>& l) { return l.get() == p; }

which is the 3rd argument of the function std::find_if(). The 3rd argument can be a function pointer. Is this a inline way of defining a function pointer in the argument of another function ? I haven’t seen this type of usage before. Is my understanding correct ?

Thanks.

  • 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-06-09T22:56:34+00:00Added an answer on June 9, 2026 at 10:56 pm

    std::find_if is templated and accepts as third argument a generic functor (also known as “function object”), which is whatever can be called as a function. This class of “things” includes function pointers, any object that overloads the function call operator and lambdas.

    In this specific case, you are seeing it used with a lambda function, which is an anonymous function defined in place.

    Lambdas are not just “a way to define a function pointer”; instead, they create a function object “on the fly” with the given code and captured context. A key difference between lambdas and “regular functions” is the fact that lambdas can capture a context (the variable p in your example).

    Also, pointers to functions with the same signature have the same type, while lambdas have unspecified type. Still, a lambda that doesn’t capture anything converts implicitly to an ordinary function pointer (see C++11 §5.1.2/6, thanks at Cheers and hth. – Alf for pointing this out); this makes them useful to use even with functions that accept only function pointers and not generic functors.

    You probably haven’t seen lambdas around yet because they are a recent addition to the C++ language (they have been standardized in the C++11 standard, approved just this year).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently came across some code that looks something like this: <head> <?php /*
I recently came across some code that looked like: if(sizeof(var,2) == 4) { ...
I recently came across Tesseract and OpenCV . It looks like Tesseract is a
I recently came across this image which seems like a normal GIF: Even imgur
I recently came across this interview question (posted in a forum somehwere... looks like
I recently came across code written by a fellow programmer in which he had
I recently came across a situation where I had to use XPath as part
I recently came across the following piece of code. It doesn't look valid because
I recently came across some Java code that simply put some strings into a
I recently came across this website: http://studiostyles.info , which contains a list of color

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.