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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:26:21+00:00 2026-05-12T17:26:21+00:00

I am trying to simplify (via make_fn() ) the generation of functors that preprocess

  • 0

I am trying to simplify (via make_fn()) the generation of functors that preprocess parameters (via wrap()) for member functions of arity n.
Generating the functors is basically working, but until now only by explicitly specifying the parameter types for the member function.
Now i’d like to generate the correct functor from the member function type it handles:

struct X {};

template<class C, typename T1, bool (C::*F)(T1)>
inline // there are more for T1..TN
bool wrap(C* c, X x) 
{
    return (c->*F)(process<T1>(x));
}

template<class C, typename T1, bool (C::*F)(T1)> 
inline // there are more for T1..TN
boost::function<bool (C*, X)> make_fn(F f) // <- problem here, F is not a type
{
    return boost::bind(&wrap<C, T1, F>, _1, _2);
}

With this however, vc++ and g++ don’t see F as a type for the parameter of make_fn(). I must miss something obvious here and am feeling somewhat blind.

The idea was that it should work like this:

struct A 
{
    bool f1(bool) { return true; }
};

void test()
{
    A a;
    X x;
    make_fn(&A::f1)(&a, x);
}

Any ideas on how to make that work?

Background:
I have a fixed interface which, when simplified, looks like this:

bool invoke(C* c, const char* const functionName, int argCount, X* args);

X is a variant type which i have to convert to certain backend types (int, std::string, …).
To handle these calls i have a map of functors that are looked up by name and map these calls to member functions of some instance.
The intention of the wrapping is to avoid manual conversions and instead generate functors which do the conversion for me or throw. I have this working with a macro based solution, but that solution requires to specify the types and the parameter count explicitly.
Via function overload resolution i hope to generate the correct converting functor implicitly from the member function signature.

  • 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-12T17:26:21+00:00Added an answer on May 12, 2026 at 5:26 pm

    It appears to me that you are attempting to turn a pointer passed to a function into a non-type template argument, which I’m afraid is not going to work (see comments to your question).

    What you could do, is to store the function pointer in a function object. The following appears to compile:

    #include <boost/bind.hpp>
    #include <boost/function.hpp>
    
    struct X {};
    
    template <class T>
    bool process(X) { return true; }
    
    
    template <class C, class T1, class Func>
    struct wrap1
    {
        typedef bool result_type;
        Func f;
    
        wrap1(Func f): f(f) {}
    
        bool operator()(C* c, X x)
        {
            return (c->*f)(process<T1>(x));
        }
    };
    
    template<class C, typename T1>
    inline // there are more for T1..TN
    boost::function<bool (C*, X)> make_fn(bool (C::*f)(T1))
    {
        return boost::bind(wrap1<C, T1, bool (C::*)(T1)>(f), _1, _2);
    }
    
    
    struct A
    {
        bool f1(bool) { return true; }
    };
    
    void test()
    {
        A a;
        X x;
        make_fn(&A::f1)(&a, x);
    }
    

    However, I’m not sure if that is any good and how you would create the rest of the wrappers. For the latter you might just get a compiler that supports variadic templates. 🙂

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

Sidebar

Related Questions

I am trying to simplify some of the bookmarklets that I have created over
I'm trying to simplify a form (using ASP.NET MVC but I guess that might
I am having some trouble trying to simplify some logic that is contained in
At work we are trying to simplify an application that was coded with an
I am trying to simplify a switch-statement that takes a lot of space and
I'm trying to simplify some inherited PHP code that assigns a value to one
This is an under-performing query that I've been trying to simplify but am at
I'm trying to simplify some code by putting the ViewModel models into the code
I'm trying to simplify a Card class, and am wondering if there's any way
I am trying to simplify a large project by having cmake compile it all

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.