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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:05:13+00:00 2026-05-29T06:05:13+00:00

I have a construct in a form: template<class T> void do_something_with_it(T*&& ptr) { //here

  • 0

I have a construct in a form:

template<class T>
    void do_something_with_it(T*&& ptr)
    {
//here I can do something with this ptr
    }

    template<class T,class... Args>
    void do_something_with_them(T*&& ptr, Args&&... args)
    {
        do_something_with_it(std::forward<T&&>(ptr));
        do_something_with_them(std::forward<Args&&>(args)...);
    }

but for some reason I cannot forward those arguments. Is there a way to do it?
I’m using gcc 4.6.1.

  • 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-29T06:05:14+00:00Added an answer on May 29, 2026 at 6:05 am

    Chances are that you get compile time errors, because T*&& is not a perfect forwarding vehicle. Only T&& is. So your ptr parameter only accepts rvalues. And in addition to that, your std::forward<T&&> should be std::forward<T*>, but of course now that you have the other error anyway this is irrelevant. And in addition to that the call to do_something_with_them misses to hit a base case of do_something_with_them with zero parameters, because if args is empty…

    If you really only want to accepts pointers, you can work with enable_if and is_same or is_convertible. But then of course I don’t think it’s “forwarding” anymore. What about

    template<typename T, typename ...Args>
    auto do_something_with_them(T&&t, Args&&...args)
      -> decltype(do_something_with_it(std::forward<T>(t)))
    { ... }
    

    That way you let do_something_with_it decide whether or not it accepts the argument (if you want you can put the recursive call into that decltype too. I leave it as an exercise to the reader as to what operator might be needed here). But of course do_something_with_it has the same problem too about not being generic.

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

Sidebar

Related Questions

I have created a form like this: class Form_Login extends Zend_Form { public function
I have Login.php form like this: class Form_Login extends Zend_Form { public function init()
I have created a class named Times and I have to construct 4 overloaded
I have an enum construct like this: public enum EnumDisplayStatus { None = 1,
I have a feeling that this query is pretty easy to construct, I just
I have a question about the loop construct in Python in the form of:
We have a problem using a class template which itself uses function objects in
I am trying to construct equivalent of this code in JSF2 <form action=/search.xhtml method=get>
Ok, so I have been working a Mysql class. I am making a form
I have an order form that extends Zend_form: class Form_Order extends Zend_Form { public

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.