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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:07:01+00:00 2026-06-02T19:07:01+00:00

// some arbitrary function template<typename T> void log( T&& obj ) { std::cout <<

  • 0
// some arbitrary function 
template<typename T>
void log( T&& obj )
{
    std::cout << obj << std::endl;    
}

// arbitrary transformation
template<typename T>
T convert(T&& obj) { 
     return obj; 
}

template<template <typename> typename F, typename... T>
void callOn( F<T> func,  ///  issue: what's the type of func?                 
             T&&... params)
{
    func(std::forward<T>(convert(std::forward<T>(params)))...);
}

int main()
{   
    callOn(log, -1, -2.0);      
     return 0;
}

Is this possible at all?

Compiler complains: no matching function for call to ‘callOn(, ..>). Why ?

Update: suppose log is not unary function

template<typename T>
void log(T&& value) { std::cout << value << std::endl; }

template<typename First, typename... Rest>
void log(First&& f, Rest&&... rest)
{
    std::cout << f << ",";
    log(std::forward<Rest>(rest)...);
}

callOn takes type “template ” which doesn’t match the type of log? How to specify the type of func?

  • 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-02T19:07:02+00:00Added an answer on June 2, 2026 at 7:07 pm

    Use a function object. Here’s a compilable example:

    #include <utility>
    #include <iostream>
    
    struct Log
    {
        template<typename T> void operator()(T&& t) { 
            std::cout << t << std::endl; 
        }
    
        template<typename T, typename... Rest> void operator()(T&& t, Rest&&... rest)
        {
            std::cout << t << ", ";
            (*this)(std::forward<Rest>(rest)...);
        }
    };
    
    template<typename T>
    T convert(T&& obj) {
         return obj;
    }
    
    template<typename F, typename... T>
    void callOn(F funcobj, T&&... params)
    {
        funcobj(std::forward<T>(convert(std::forward<T>(params)))...);
    }
    
    int main()
    {
        callOn(Log(), -1, -2.17, "abc");
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm importing some arbitrary HTML into a DOMDocument using the loadHTML() function, eg.: $html
In C++ I can do the following: template<typename T, typename V> struct{ void operator()(T
I have some arbitrary text that i'd like to convert into a table with
Given some arbitrary SQL I would like to get the data types of the
After setting db to some arbitrary value, i am not able to perform any
Sometimes I need to quickly extract some arbitrary data from XML files to put
I just want a simple SVG image that has some arbitrary text on an
Say I use glRotate to translate the current view based on some arbitrary user
How can I have SQL repeat some set-based operation an arbitrary number of times
I have a need to evaluate user-defined logical expressions of arbitrary complexity on some

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.