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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:49:27+00:00 2026-05-29T17:49:27+00:00

I’m attempting to put together a generic method invoker (for a C++ OO/v8 bridge),

  • 0

I’m attempting to put together a generic method invoker (for a C++ OO/v8 bridge), using variadic template metaprogramming to build the parameter list, converting to native types, and finally execute the attached method, once the incoming param list is empty (and outgoing is therefore built):

template<typename... PARAMS>
class InvocationBuilder {
public:

void invoke(const Arguments &source, PARAMS&... params) {
    cout << "Invoke" << endl;
    (instance->*(method))(*params...);
}

template<class HEAD, class ... TAIL>
void invoke(const Arguments &source, PARAMS... params) {
    cout << "Expand" << endl;
    Type<HEAD> param(source[sizeof...(PARAMS)]);
    InvocationBuilder<PARAMS..., HEAD> builder;
    builder.template invoke<TAIL...>(source, params..., *param);
}

The Type class is merely a wrapper to create stack scoped variants of v8 parameters (so that, for instance, char* strings can be used while in scope during the invocation, but are automatically cleaned up once the call has returned).

Now, when the actual bridge invokes this, with a parameter list, using:

InvocationBuilder<> builder;
builder.template invoke<ARGS...>(args);

Where args is the v8::Arguments reference.

The compiler correctly chains each step of the parameter generation, but fails to match the non-templated invoke() method, to actually execute the native C++ method.

The error message is as follows:

include/link/function.hh: In member function 'void sjs::link::InstanceFunctionVariadic<CLASS, ARGS>::InvocationBuilder<PARAMS>::invoke(const v8::Arguments&, PARAMS ...) [with HEAD = int, TAIL = {}, PARAMS = {int, int}, CLASS = SomeClass, ARGS = {int, int, int}]':
include/link/function.hh:65:6:   recursively instantiated from 'void sjs::link::InstanceFunctionVariadic<CLASS, ARGS>::InvocationBuilder<PARAMS>::invoke(const v8::Arguments&, PARAMS ...) [with HEAD = int, TAIL = {int}, PARAMS = {int}, CLASS = SomeClass, ARGS = {int, int, int}]'
include/link/function.hh:65:6:   instantiated from 'void sjs::link::InstanceFunctionVariadic<CLASS, ARGS>::InvocationBuilder<PARAMS>::invoke(const v8::Arguments&, PARAMS ...) [with HEAD = int, TAIL = {int, int}, PARAMS = {}, CLASS = SomeClass, ARGS = {int, int, int}]'
include/link/function.hh:47:5:   instantiated from 'v8::Handle<v8::Value> sjs::link::InstanceFunctionVariadic<CLASS, ARGS>::run(const v8::Arguments&) [with CLASS = SomeClass, ARGS = {int, int, int}]'
test.cc:41:1:   instantiated from here
include/link/function.hh:65:6: error: no matching function for call to 'sjs::link::InstanceFunctionVariadic<SomeClass, int, int, int>::InvocationBuilder<int, int, int>::invoke(const v8::Arguments&, int&, int&, int)'
include/link/function.hh:65:6: note: candidate is:
include/link/function.hh:61:10: note: template<class HEAD, class ... TAIL> void sjs::link::InstanceFunctionVariadic<CLASS, ARGS>::InvocationBuilder::invoke(const v8::Arguments&, PARAMS ...) [with HEAD = HEAD, TAIL = {TAIL ...}, PARAMS = {int, int, int}, CLASS = SomeClass, ARGS = {int, int, int}]

The message clearly shows that the first three steps, for a C++ instance method void test(int a, int b, int c), are working correctly, extracting the parameters using Type and passing the results along – but I can’t work out why the final invoke() is not being correctly used.

I’ve tried to fully specialize it, but then I get error messages about specialization outside of namespace scope (which I assume is because the method is a member of a templated class).

I’ve also tried shifting the incoming/outgoing parameter lists, so that the incoming is in the class variadic template, and the outgoing in the method to specialise the class for invocation instead – but I run into the “sorry, unimplemented” message about unpacking the variadic into the static template.

I’ve also tried working around that by using a generic single variadic template, then specialising for the HEAD/TAIL case, and specialising for the empty set case, but then I get immediate ambiguity (probably because the HEAD/TAIL values are not actually passed as parameters – merely in the template).

But so far, no dice. Anyone have any other ideas, or can explain where I’m going wrong?

  • 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-29T17:49:30+00:00Added an answer on May 29, 2026 at 5:49 pm

    Note that:

    • you explicitly try to invoke a template
    • your templated invoke always requires PARAMS... to be passed as function arguments

    One possible alternative:

    #include <functional>
    
    template<class... Types> struct List {};
    
    template<class... PARAMS> struct Invoker {
        typedef std::function<void (PARAMS&...)> Fn;
        Fn fn_;    
        Invoker(const Fn&& fn) : fn_(fn) {}
    
        void invoke(List<>, PARAMS&... params) {
            fn_(params...);
        }
    
        template<class HEAD, class... TAIL, class... ARGS>
        void invoke(List<HEAD, TAIL...>, ARGS... params) {
            HEAD param; // or your Type<HEAD> ... etc.
            invoke(List<TAIL...>(), params..., param);
        }
    };
    
    void f(int, int, int) {} // some function you want to call
    
    int main() {
        Invoker<int,int,int> inv(&f);
        inv.invoke(List<int,int,int>());
    }
    

    … without a small compilable example of your use-case (with dummy-types etc.) it would be a bit time-consuming to make this match your code more closely.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

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.