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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:52:19+00:00 2026-06-15T23:52:19+00:00

I wonder if it is possible using boost::mpl/preprocessor or some noce C++11 features to

  • 0

I wonder if it is possible using boost::mpl/preprocessor or some noce C++11 features to create function proxy from class type and function name.

Say we had:

  inline void set_email(const ::std::string& value);
  inline void set_email(const char* value);

inside class Email. We know there is set_email function n it, we want to create a prox class with API like

PROXY(Email, set_email, MyEmail)

Email * email = new Email();
MyEmail * myEmail = new MyEmail(email);

and have abilety to call any of set_email overloads.Is it possible and how to create such class that would proxy any number of overload functions not knowing there types (only names)?

  • 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-15T23:52:20+00:00Added an answer on June 15, 2026 at 11:52 pm

    How about this:

    proxy_macro.hpp

    #include <type_traits>
    #include <utility>
    
    #define PROXY(proxified, member_function, proxy_name)                                                                           \
      class proxy_name                                                                                                              \
      {                                                                                                                             \
      private:                                                                                                                      \
        proxified & ref_;                                                                                                           \
                                                                                                                                    \
      public:                                                                                                                       \
        proxy_name(proxified &ref)                                                                                                  \
          : ref_(ref)                                                                                                               \
          {                                                                                                                         \
          }                                                                                                                         \
                                                                                                                                    \
        /* general version */                                                                                                       \
        template<typename ... Args>                                                                                                 \
        auto member_function(Args&& ... args)                                                                                       \
        -> typename std::enable_if<!std::is_void<decltype(ref_.member_function(std::forward<Args>(args)...))>::value,               \
                                   decltype(ref_.member_function(std::forward<Args>(args)...))>::type                               \
          {                                                                                                                         \
            return (ref_.member_function(std::forward<Args>(args)...));                                                             \
          }                                                                                                                         \
                                                                                                                                    \
        /* void return type version */                                                                                              \
        template<typename ... Args>                                                                                                 \
        auto member_function(Args&& ... args)                                                                                       \
        -> typename std::enable_if<std::is_void<decltype(ref_.member_function(std::forward<Args>(args)...))>::value,                \
                                   void>::type                                                                                      \
          {                                                                                                                         \
            ref_.member_function(std::forward<Args>(args)...);                                                                      \
          }                                                                                                                         \
                                                                                                                                    \
      };
    

    This compiles and work fine for me on g++ 4.7:

    #include "proxy_macro.hpp"
    
    #include <iostream>
    #include <string>
    
    class   Email
    {
    public:  
      void set_email(const ::std::string& value)
      {
        std::cout << value << std::endl;
      }
    
      void set_email(const char* value)
      {
        std::cout << value << std::endl;
      }
    
      int   set_email()
      {
        return (42);
      }
    
    };
    
    PROXY(Email, set_email, MyEmail)
    
    int main(void)
    {
      Email   mail;
      MyEmail my_mail(mail);
    
      std::string str = "test string";
      const char * ptr = "test char pointer";
    
      my_mail.set_email(str);
      my_mail.set_email(ptr);
    
      std::cout << "test return: " << my_mail.set_email() << std::endl;
    
      return (0);
    }
    

    Edit (smaller version thanks to comments)

    proxy_macro.hpp

    #include <type_traits>
    #include <utility>
    
    #define PROXY(proxified, member_function, proxy_name)                \
      class proxy_name                                                   \
      {                                                                  \
      private:                                                           \
        proxified & ref_;                                                \
                                                                         \
      public:                                                            \
        proxy_name(proxified &ref)                                       \
          : ref_(ref)                                                    \
          {                                                              \
          }                                                              \
                                                                         \
        template<typename ... Args>                                      \
        auto member_function(Args&& ... args)                            \
        -> decltype(ref_.member_function(std::forward<Args>(args)...))   \
          {                                                              \
            return (ref_.member_function(std::forward<Args>(args)...));  \
          }                                                              \
      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder how to get LATEX table using xtable function from the following R
I wonder if it's possible obfuscate only some strings from your source code into
I wonder if it's possible to create an extension method which has functionality &
I wonder if its possible to remove all the objects from the same kind
I wonder whether it is possible to debug a C++ program with Textmate, using
I wonder how is it possible to send a picture. I am using json
I'm using std::random_shuffle and srandom, and wonder if it's possible to constrain srandom()'s effect
I wonder if it is possible using regular expression in Django templates: <a href=#{{form.deal_template_name.value}}
just wonder is it possible to create a trigger to check on a specify
I wonder if it is possible to rearrange HTML table cells using only CSS.

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.