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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:57:09+00:00 2026-06-04T01:57:09+00:00

I just found myself creating a class template <typename T> struct invoker { void

  • 0

I just found myself creating a class

template <typename T> struct invoker {
  void operator()(T& it) const {it();}
};

so I could pass an invoker<foo> to something (which isn’t under my control) which wants to call invoker<foo>::operator()(foo&) on it repeatedly with different foo instances, to get it to forward those calls to the foo‘s foo::operator()() method.

I know it’s only a few lines, but this seems like the sort of thing which is probably already provided for by STL’s functional, or boost::bind somehow. Except I can’t see the trick, if there is one. (I’m sure I’m not the first person to use something very like this; does it have a name ?)

  • 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-04T01:57:12+00:00Added an answer on June 4, 2026 at 1:57 am

    Yeah, you’re reinventing the wheel. std::mem_fun_ref does what you want.

    std::vector<foo> foos;
    
    ...
    
    std::for_each(foos.begin(), foos.end(), std::mem_fun_ref(&foo::operator()));
    

    Alternatively:

    std::vector<foo*> foos;
    
    ...
    
    std::for_each(foos.begin(), foos.end(), std::mem_fun(&foo::operator()));
    

    Not having to mess with whether your param is ptr or not is one great benefit of boost::mem_fn.

    Anything much more complex than that though and you begin running into trouble with the C++03 binders and need something more expressive like boost.bind.

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

Sidebar

Related Questions

I just found myself creating a class called InstructionBuilderFactoryMapFactory. That's 4 pattern suffixes on
I found myself writing this just a bit ago: template <long int T_begin, long
I just recently found myself writing this line of code, which i did not
I'm creating a DB web application with grails for my company and found myself
I just found myself a new challenge: Make a Word Processor that is in
I just found myself a little bit surprised being unable to simply use a
I'm just getting my hands on Django Managers and I've found myself doing this
I just found myself copying and pasting the same code twice. Right now I
I just found myself absent-mindedly using from as an identifier. I realise that it
I've found myself having to write some VBA code recently and just wondered if

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.