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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:37:50+00:00 2026-05-26T18:37:50+00:00

How can I template these functions? boost::function< void(int) > binder( void(*func)(int, char), int a1,

  • 0

How can I template these functions?

boost::function< void(int) > binder( void(*func)(int, char), int a1, char a2 )
{
    return boost::bind( func, a1, a2 );
}

void proxy( boost::function< void(int) > func, int a1 )
{
    boost::bind( func, a1 )();
}

I tried the following with no success:

template< typename R, typename A1, typename A2 >
static boost::function< void(int) > binder( R(*func)(A1,A2), A1 a1, A2 a2 )
{
    return boost::bind( func, a1, a2 );
}

template< typename A1 >
static void proxy( boost::function< void(A1) > func, A1 a1 )
{
    boost::bind( func, a1 )();
}

It would be nice if I could do without binder(). This is how I intend to use them:

void print( int i, char c );
boost::signals2::signal.connect(
    boost::bind(
        &proxy,
        boost::bind(
            &binder,
            &print,
            _1,
            'a'
            ),
        _1
        )
    );

I checked out the following with no luck:

how-to-use-manipulate-return-value-from-nested-boostbind

perform-argument-substitution-on-nested-boostbind-without-composition

can-i-use-boost-bind-with-a-function-template

  • 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-26T18:37:51+00:00Added an answer on May 26, 2026 at 6:37 pm

    You need to spell function pointers right:

    R(*func)(A1, A2)
    

    You will also need to specify the template parameters for forming a function pointer: Remember that binder is not a function, but a template!

    &binder<void, int, char>
    &proxy<int>
    

    Finally, you’re not getting your signal variable right. Declare it like this:

    boost::signals2::signal<void(int)> sig;
    

    Then use:

    sig.connect( /* all that stuff */ );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following setup: I am given an interface template<class T> void FooClass<T>::foo(boost::function<double (int)>
I can't seem to declare a generic pointer to function. Having these 2 functions
Given the following template: template<class T> class Container { private: boost::function<T> f; }; ...
I'm trying to expose the following c++ function to python using boost.python: template <typename
When writing a header library (like Boost ), can one define free-floating (non-method) functions
I'm writing a template function which should swap two elements of a boost::mpl::vector (similarly
I purchased a template / theme from RocketTheme, but I can't figure out how
In VB.NET is there a library of template dialogs I can use? It's easy
there is insert iterator in database template library or other library, Can someone tell
I come from a C++ background where I can use template mixins to write

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.