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 6011641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:17:21+00:00 2026-05-23T02:17:21+00:00

Is there a small functor in the C++ standard or in Boost that wraps

  • 0

Is there a small functor in the C++ standard or in Boost that wraps around another functor, but dereferences a pointer before it calls that functor?

I’m thinking of something like this:

template<class F>
struct DerefCmp {
  template<class T>
  bool operator()(T* v) const {
    return F(*v);
  }
};

I’d use it in a container of pointers, for example, where I want to compare by value:

std::set<int*, DerefCmp< std::equal<int> > > s;
  • 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-23T02:17:22+00:00Added an answer on May 23, 2026 at 2:17 am

    I am not aware of any function object in the C++ Standard Library or in Boost that does this (that’s not to say there isn’t one; I am not familiar with everything in the Boost libraries :-P).

    However, writing your own is rather straightforward. Consider the following:

    template <typename Predicate>
    class indirect_binary_predicate
    {
    public:
        indirect_binary_predicate(const Predicate& pred = Predicate()) 
            : pred_(pred) 
        {
        }
    
        template <typename Argument0, typename Argument1>
        bool operator()(Argument0 arg0, Argument1 arg1) const 
        { 
            return pred_(*arg0, *arg1); 
        }
    
    private:
        Predicate pred_;
    };
    

    Usage example:

    std::set<int*, indirect_binary_predicate<std::equal_to<int> > > s;
    

    Note that it is ill-advised to have a container of raw pointers if the pointers are to dynamically allocated objects and the container has ownership of the pointed-to objects; it isn’t exception-safe to do this. That said, this predicate adapter should work just as well for smart pointers, iterators, or any other type that supports dereferencing.

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

Sidebar

Related Questions

Is there any even small possibility that finally will not be invoked but application
I've read all recommended articles on SynchronizationContext, but there is one small question I
Hey there. I'm trying to write a small program that will read the four
Is there any small library, that wrapps various processors' CAS-like operations into macros or
I found Core Plot as very nice plotting library. But there is small issue:
There is a small topic branch that I'd like to apply on top of
Is there a small, lightweight solution for javascript class inheritance that will work well
There is a small 3rd-party program in the notification area of the taskbar that
While running the app on device, I noticed that there is a small jump
I want to do a simple image animation.Assume that there is small image of

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.