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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:23:04+00:00 2026-06-02T05:23:04+00:00

I have in essence the following code: typedef std::function<void ()> fnGlobalChangeEvent; typedef std::vector<fnGlobalChangeEvent> GlobalTriggers;

  • 0

I have in essence the following code:

typedef std::function<void ()> fnGlobalChangeEvent;
typedef std::vector<fnGlobalChangeEvent> GlobalTriggers;

inline void ExecuteGlobal(fnGlobalChangeEvent ev)
{
    ev();
}

GlobalTriggers triggers;
std::for_each(triggers.begin(), triggers.end(), std::bind(&ExecuteGlobal, _1));

The use of ExecuteGlobal feels totally redundant here, but I can’t find the right syntax to drop out the call.

std::for_each(triggers.begin(), triggers.end(), ExecuteGlobal(_1));
std::for_each(triggers.begin(), triggers.end(), std::bind(_1));

Both fail to compile.

There is also a more complex case:

typedef std::function<void (Zot&)> fnChangeEvent;
typedef std::vector<fnChangeEvent> Triggers;

inline void Execute(fnChangeEvent ev, Zot& zot)
{
    ev(zot);
}

Triggers triggers;
std::for_each(triggers.begin(), triggers.end(), std::bind(&Execute, _1, zot));

Is it possible to do without the helper functions in these cases?

  • 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-02T05:23:06+00:00Added an answer on June 2, 2026 at 5:23 am

    Sure, a lambda:

    std::for_each(
        triggers.begin(), triggers.end(),
        [](fnChangeEvent ev) { ev(); }
    );
    std::for_each(
         triggers.begin(), triggers.end(),
         [&zot](fnChangeEvent ev) { ev(zot); }
    );
    

    Or even better, range for:

    for (auto ev : triggers) {
        ev();
    }
    
    // well, I think you can figure out the second one
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The essence of the situation comes down to the following: I have a data
I currently have a function template, taking a reference, that does something in essence
I have the following tables Essence , EssenseSet , and Essense2EssenceSet Essense2EssenceSet is the
I have a need for some kind of information that is in essence static.
I have a Tridion implementation that is, in essence, multi-tennent. Different interest groups use
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Have you ever created or encountered a self modifying code in Java? If yes,
I have the following Sql Query that returns the type of results that I
curious if anyone might have some insight in how I would do the following
For the web application (ASP.NET MVC) I'm currently developing, we have the following architecture

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.