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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:23:30+00:00 2026-05-11T05:23:30+00:00

I am attempting to write a dynamic dispatcher for a function that’s templated on

  • 0

I am attempting to write a dynamic dispatcher for a function that’s templated on integer values (not on types). While I could either write a code generator or use a big macro chain to create the dispatcher source, it seems that a templated solution would be more elegant.

I’ve stripped down my dispatcher to a simple form (which doesn’t actually do any dispatching):

// works fine with full template specialization template <int N> struct TestDispatcher1D {   int f(int n) {     if (n == N) return n; // replace me with actual dispatch     TestDispatcher1D<N-1> t;     return t.f(n);   } };  template<> struct TestDispatcher1D<-1> {   int f(int n) { return -1; } };  // partial template specialization is problematic template <int M, int N> struct TestDispatcher2D {   int f(int m, int n); };  template<int M> struct TestDispatcher2D<M,-1> {   int f(int m, int n) { return -1; } };  template<int N> struct TestDispatcher2D<-1,N> {   int f(int m, int n) { return -1; } };  template<> struct TestDispatcher2D<-1,-1> {   int f(int m, int n) { return -1; } };  template <int M, int N> int TestDispatcher2D<M,N>::f(int m, int n) {   if ((n == N) && (m == M)) return n + m; // replace me with actual dispatch   if (m < M) {     if (n < N) {       TestDispatcher2D<M-1,N-1> t;       return t(m,n);     } else {       TestDispatcher2D<M-1,N> t;       return t(m,n);     }   } else {     TestDispatcher2D<M,N-1> t;     return t(m,n);   } }  // test code void testIt() {   {      TestDispatcher1D<16> t;      t.f(16);    }   {     TestDispatcher1D<16>t;      t.f(0);   }   {     TestDispatcher2D<16,16>t;      t.f(8,8);   } } 

When compiling this on gcc 4.1.1, I get the following errors:

 t.cpp: In member function 'int TestDispatcher2D::f(int, int) [with int M = 16, int N = 16]': t.cpp:63:   instantiated from here t.cpp:40: error: no match for call to '(TestDispatcher2D) (int&, int&)' t.cpp:63:   instantiated from here t.cpp:43: error: no match for call to '(TestDispatcher2D) (int&, int&)' t.cpp:63:   instantiated from here t.cpp:47: error: no match for call to '(TestDispatcher2D) (int&, int&)' 

Apparently, when I try to create the recursive objects, the compiler isn’t treating this as a request to instantiate a new template.

Any suggestions?

  • 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. 2026-05-11T05:23:31+00:00Added an answer on May 11, 2026 at 5:23 am

    You’re simply not calling the f() function in your recursive call, you’re trying to ‘call the object’:

    You write:

    TestDispatcher2D<...> t; return t(m,n); 

    But you want:

    TestDispatcher2D<...> t; return t.f(m,n); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write a performance testing function that can take any function, run
I'm attempting to write a function that generates a list of DateTimes using the
I've been attempting to write a Lisp macro that would perfom the equivalent of
I am attempting to write an application that uses libCurl to post soap requests
I'm attempting to write a Python C extension that reads packed binary data (it
I am attempting to write a one-line Perl script that will toggle a line
Attempting to print out a list of values from 2 different variables that are
When attempting to write/read cookies that have brackets in the name, it seems like
I'm attempting to write a program in Linux using C++ that counts the number
I'm attempting to write a CompiledQuery using Linq-to-Entities that will replace a stored procedure

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.