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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:12:14+00:00 2026-05-16T01:12:14+00:00

Boost comes with an example file in boost_1_41_0\libs\function_types\example called interpreter.hpp and interpreter_example.hpp I am

  • 0

Boost comes with an example file in

boost_1_41_0\libs\function_types\example

called interpreter.hpp and interpreter_example.hpp

I am trying to create a situation where I have a bunch of functions of different arguments, return types, etc all register and be recorded to a single location. Then have the ability to pull out a function and execute it with some params.

After reading a few questions here, and from a few other sources I think the design implemented in this example file is as good as I will be able to get. It takes a function of any type and allows you to call it using a string argument list, which is parsed into the right data types.
Basically its a console command interpreter, and thats probably what its meant to illustrate.

I have been studying the code and poking around trying to get the same implementation to accept class member functions, but have been unsuccessful so far.
I was wondering if someone could suggest the modifications needed, or maybe worked on something similar and have some same code.

In the example you’ll see

interpreter.register_function("echo", & echo);
interpreter.register_function("add", & add);
interpreter.register_function("repeat", & repeat);

I want to do something like

test x;
interpreter.register_function("classFunc", boost::bind( &test::classFunc, &x ) );

But this breaks the any number of arguments feature.
So I am thinking some kind of auto generating boost::bind( &test::classFunc, &x, _1, _2, _3 … ) would be the ticket, I just am unsure of the best way to implement it.

Thanks

  • 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-16T01:12:15+00:00Added an answer on May 16, 2026 at 1:12 am

    I’ve been working on this issue and i’ve somewhat succeeded to make the boost interpreter accept the member function such as:

    // Registers a function with the interpreter, 
    // will not compile if it's a member function.
    template<typename Function>
    typename boost::enable_if< ft::is_nonmember_callable_builtin<Function> >::type
    register_function(std::string const& name, Function f);
    
    // Registers a member function with the interpreter. 
    // Will not compile if it's a non-member function.
    template<typename Function, typename TheClass>
    typename boost::enable_if< ft::is_member_function_pointer<Function> >::type
    register_function(std::string const& name, Function f, TheClass* theclass);
    

    The enable_if statement is used to prevent the use of the wrong method at the compile time. Now, what you need to understand :

    • It uses the boost::mpl to parse trough the argument’s parameter types of the callable builtin (which is basically a function pointer)
    • Then, prepares a fusion vector at the compile-time (which is a vector that can stock different objects of different types at the same time)
    • When the mpl is done parsing every arguments, the “parsing” apply method will fork in the “invoke” apply method, following the templates.
    • The main issue is that the first argument of a member callable builtin is the object which holds the called method.
    • As far a I know, the mpl cannot parse the arguments of something else than a callable builtin (i.e A Boost::Bind result)

    So, what needs to be done is simply add one step to the “parsing” apply, which would be to add the concerned object to the apply loop! Here it goes:

    template<typename Function, typename ClassT>
    typename boost::enable_if< ft::is_member_function_pointer<Function> >::type
    interpreter::register_function( std::string const& name, 
                                    Function f, 
                                    ClassT* theclass);
    {   
        typedef invoker<Function> invoker;
        // instantiate and store the invoker by name
        map_invokers[name] 
                = boost::bind(&invoker::template apply_object<fusion::nil,ClassT>
                              ,f,theclass,_1,fusion::nil());
    }
    

    in interpreter::invoker

    template<typename Args, typename TheClass>
    static inline
    void 
    apply_object( Function func, 
                  TheClass* theclass, 
                  parameters_parser & parser, 
                  Args const & args)
    {
        typedef typename mpl::next<From>::type next_iter_type;
        typedef interpreter::invoker<Function, next_iter_type, To> invoker;
    
        invoker::apply( func, parser, fusion::push_back(args, theclass) );      
    }
    

    This way, it will simply skip the first argument type and parse everything correctly.
    The method can be called this way: invoker.register_function("SomeMethod",&TheClass::TheMethod,&my_object);

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

Sidebar

Ask A Question

Stats

  • Questions 480k
  • Answers 480k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Possibly IIS is treating the colon as if it should… May 16, 2026 at 6:08 am
  • Editorial Team
    Editorial Team added an answer Void is considered a data type (for organizational purposes), but… May 16, 2026 at 6:08 am
  • Editorial Team
    Editorial Team added an answer If you want to edit Javascript within Eclipse, just install… May 16, 2026 at 6:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.