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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:00:02+00:00 2026-05-28T01:00:02+00:00

I have an application where I’m building a function, marshal_and_apply , which calls some

  • 0

I have an application where I’m building a function, marshal_and_apply, which calls some other function (or functor), f with some arguments. marshal_and_apply‘s job is to apply some special marshaling for the arguments depending on the type of f‘s parameters.

If one of f‘s parameters is of a special type, marshal_me<T>, then marshal_and_apply will marshal the parameter through some specially allocated storage before passing it to f. In order to perform the allocation, the storage requirements of all the parameters must be known to marshal_and_apply before any can be marshaled.


Some examples:

template<typename Function, typename... Args>
void marshal_and_apply(Function f, Args... args);

void func1(int x, int y);
void func2(marshal_me<int> x, int y);
void func3(marshal_me<int> x, marshal_me<int> y, marshal_me<int> z);

// this call would be equivalent to:
// func1(7,13)
marshal_and_apply(func1, 7, 13);

// this call would be equivalent to:
// auto storage = my_allocator(sizeof(int));
// auto x = marshal_me<int>(7, storage);
// func2(x, 13);
marshal_and_apply(func2, 7, 13);

// this call would be equivalent to:
// auto storage = my_allocator(sizeof(int) + sizeof(int) + sizeof(int));
// auto x = marshal_me<int>(7, storage);
// auto y = marshal_me<int>(13, storage + sizeof(int));
// auto z = marshal_me<int>(42, storage + sizeof(int) + sizeof(int));
// func3(x,y,z);
marshal_and_apply(func3, 7, 13, 42);

To solve this problem, it seems that marshal_and_apply requires a mechanism to inspect the types of f‘s parameters. I suspect this isn’t possible in general, but it may be possible to recognize whether one of a special set of types (in this case, marshal_me<T>) is convertible to the type of a particular parameter.

How should I build marshal_and_apply?

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

    Maybe something like this:

    template<typename Function, typename... Args>
    void marshal_and_apply(Function f, Args &&... args)
    {
        f(InspectAndModify<Args>::process(sizeof...(Args), std::forward<Args>(args))...);
    }
    

    Now define:

    template <typename T> struct InspectAndModify
    {
        static T&& process(unsigned int N, T && t)
        {
            return std::forward<T>(t);
        }
    };
    
    template <typename T> struct InspectAndModify<marshal_me<T>>
    {
         static T&& process(unsigned int N, marshal_me<T> && m)
         {
             /* ... */
         }
    };
    

    Something completely different: This approach first dissects the function signature, and then performs a “static transform” on each pair of types, which is where you can insert the marshal_me specialization:

    template <typename T> struct marshal_me { marshal_me(T) { } };
    
    template <typename To, typename From> struct static_transform;
    
    template <typename T> struct static_transform<T, T>
    {
      static T go(T t) { return t; }
    };
    
    template <typename T> struct static_transform<T, T&>
    {
      static T go(T & t) { return t; }
    };
    
    template <typename T> struct static_transform<marshal_me<T>, T>
    {
      static marshal_me<T> go(T && t) { return std::forward<T>(t); }
    };
    
    template<typename T, typename... Args>
    struct marshal_impl
    {
      template <typename ...Urgs>
      static T go(T(*f)(Urgs...), Args &&... args)
      {
        return f(static_transform<Urgs, Args>::go(std::forward<Args>(args))...);
      }
    };
    
    template<typename Function, typename... Args>
    void marshal_and_apply(Function f, Args &&... args)
    {
      marshal_impl<void, Args...>::go(static_cast<typename std::decay<Function>::type>(f),
                                      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 have application which creates some windows user accounts, on uninstallation I remove the
I have application which calls a WCF service. For monitoring and tracking purposes I
I have application which has some networking code which runs asynchronously. I have attached
I have application in subfolder http://example.com/some/other/sub/folder/ . And .htaccess file: RewriteEngine on RewriteBase /some/other/sub/folder
I have application which needs to use a dll (also written by me) which
We have application named Milekeeper , which relays users to send invitations to race
I have application created with Spring and has access through jmx to set some
I have application which is for paranoic users who used to store their sensitive
I have application which is configured with svn and its working fine in my
i have application in which i have a web server api .this is my

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.