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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:32:23+00:00 2026-05-26T09:32:23+00:00

How would you implement multicast for TR1 functors? I have my callback slots implemented

  • 0

How would you implement multicast for TR1 functors? I have my callback slots implemented like

void setCallback(std::tr1::function<void (std::string)> cb)
{
    this->callback = cb;
}

but need to pass more than one callback in one of them. I don’t want to go into more complex solutions like observer, as this is the only case I need multicast so far. I also cannot use Boost.Signals (as suggested here), because I cannot use Boost. I don’t need to explicitly handle disabling callback when subscriber no longer exist.

  • 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-26T09:32:24+00:00Added an answer on May 26, 2026 at 9:32 am

    You most likely want:

    void registerCallback(std::tr1::function<void (std::string)> cb)
    {
        this->callbacks.push_back(cb);
    }
    

    with callbacks a container (whichever you like) of std::tr1::function objects instead of a single one. When dispatching, iterate over the callbacks.

    Also, if you want to be able to remove callbacks later, you can do something along these lines:

    // I use list because I don't want the iterators to be invalid
    // after I add / remove elements
    std::list<std::function<void(std::string)>> callbacks;
    
    ...
    typedef std::list<std::function<void(std::string)>>::iterator callback_id;
    
    callback_id register_callback(std::function<void(std::string)> f)
    {
        return callbacks.insert(callbacks.end(), f);
    }
    
    void unregister_callback(callback_id id)
    {
        callbacks.erase(id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering how one would implement an outline view like the one Xcode 3
I would like to have a script with an infinite loop, that kills all
I have a service with some entities that I would like to expose in
There is a piece of code that I would implement like this in java:
I'm wondering about how you would implement an effect similar to this one implemented
I would like to implement a multitiple uploader in my page. I tryed with
I have code that I would like to convert so that I am grabbing
Of curiosity, I would like to know, how anyone would implement a custom mongo
Recently I've been thinking about finite state machines (FSMs), and how I would implement
How would you implement a system with the following objectives: Manage authentication, authorization for

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.